'测试客户', 'phone' => '18888888888', 'apiKey' => $apiKey, 'timestamp' => time() ]; // 生成签名 $sign = $this->generateSignature($testParams, $apiKey); $testParams['sign'] = $sign; // 构建签名过程说明 $signParams = $testParams; unset($signParams['sign'], $signParams['apiKey']); ksort($signParams); $signStr = implode('', array_values($signParams)); // 构建完整URL参数,不对中文进行编码 $urlParams = []; foreach ($testParams as $key => $value) { $urlParams[] = $key . '=' . $value; } $fullUrl = implode('&', $urlParams); return [ 'apiKey' => $apiKey, 'originalString' => $signStr, 'sign' => $sign, 'fullUrl' => $fullUrl ]; } catch (\Exception $e) { return []; } } /** * 获取计划详情 * * @return \think\response\Json */ public function index() { try { $planId = $this->request->param('planId'); if (empty($planId)) { return ResponseHelper::error('计划ID不能为空', 400); } // 查询计划详情 $plan = Db::name('customer_acquisition_task') ->where('id', $planId) ->find(); if (!$plan) { return ResponseHelper::error('计划不存在', 404); } // 解析JSON字段 $sceneConf = json_decode($plan['sceneConf'], true) ?: []; $reqConf = json_decode($plan['reqConf'], true) ?: []; $reqConf['deviceGroups'] = $reqConf['device']; $msgConf = json_decode($plan['msgConf'], true) ?: []; $tagConf = json_decode($plan['tagConf'], true) ?: []; // 处理分销配置 $distributionConfig = $sceneConf['distribution'] ?? [ 'enabled' => false, 'channels' => [], 'customerRewardAmount' => 0, 'addFriendRewardAmount' => 0, ]; // 格式化分销配置(分转元,并获取渠道详情) $distributionEnabled = !empty($distributionConfig['enabled']); $distributionChannels = []; if ($distributionEnabled && !empty($distributionConfig['channels'])) { $channels = Db::name('distribution_channel') ->where([ ['id', 'in', $distributionConfig['channels']], ['deleteTime', '=', 0] ]) ->field('id,code,name') ->select(); $distributionChannels = array_map(function($channel) { return [ 'id' => (int)$channel['id'], 'code' => $channel['code'], 'name' => $channel['name'] ]; }, $channels); } // 将分销配置添加到返回数据中 $sceneConf['distributionEnabled'] = $distributionEnabled; $sceneConf['distributionChannels'] = $distributionChannels; $sceneConf['customerRewardAmount'] = round(($distributionConfig['customerRewardAmount'] ?? 0) / 100, 2); // 分转元 $sceneConf['addFriendRewardAmount'] = round(($distributionConfig['addFriendRewardAmount'] ?? 0) / 100, 2); // 分转元 if(!empty($sceneConf['wechatGroups'])){ $groupList = Db::name('wechat_group')->alias('wg') ->join('wechat_account wa', 'wa.wechatId = wg.ownerWechatId') ->where('wg.id', 'in', $sceneConf['wechatGroups']) ->order('wg.id', 'desc') ->field('wg.id,wg.name,wg.chatroomId,wg.ownerWechatId,wa.nickName as ownerNickName,wa.avatar as ownerAvatar,wa.alias as ownerAlias,wg.avatar') ->select(); $sceneConf['wechatGroupsOptions'] = $groupList; }else{ $sceneConf['wechatGroupsOptions'] = []; } if (!empty($reqConf['deviceGroups'])){ $deviceGroupsOptions = DeviceModel::alias('d') ->field([ 'd.id', 'd.imei', 'd.memo', 'd.alive', 'l.wechatId', 'a.nickname', 'a.alias', '0 totalFriend', '0 totalFriend' ]) ->leftJoin('device_wechat_login l', 'd.id = l.deviceId and l.alive =' . DeviceWechatLoginModel::ALIVE_WECHAT_ACTIVE . ' and l.companyId = d.companyId') ->leftJoin('wechat_account a', 'l.wechatId = a.wechatId') ->order('d.id desc') ->whereIn('d.id',$reqConf['deviceGroups']) ->select(); foreach ($deviceGroupsOptions as &$device) { $curstomer = WechatCustomerModel::field('friendShip')->where(['wechatId' => $device['wechatId']])->find(); $device['totalFriend'] = $curstomer->friendShip->totalFriend ?? 0; } unset($device); $reqConf['deviceGroupsOptions'] = $deviceGroupsOptions; }else{ $reqConf['deviceGroupsOptions'] = []; } unset( $reqConf['device'], $sceneConf['groupSelected'], ); // 合并数据 $newData['messagePlans'] = $msgConf; $newData = array_merge($newData, $sceneConf, $reqConf, $tagConf, $plan); // 移除不需要的字段 unset( $newData['sceneConf'], $newData['reqConf'], $newData['msgConf'], $newData['tagConf'], $newData['userInfo'], $newData['createTime'], $newData['updateTime'], $newData['deleteTime'] ); // 生成测试URL $newData['textUrl'] = $this->testUrl($newData['apiKey']); return ResponseHelper::success($newData, '获取计划详情成功'); } catch (\Exception $e) { return ResponseHelper::error('系统错误: ' . $e->getMessage(), 500); } } }