作者 杜佳伟

增加what's app订单类型。解耦新建订单接口

@@ -14,12 +14,14 @@ @@ -14,12 +14,14 @@
14 }, 14 },
15 "minimum-stability": "stable", 15 "minimum-stability": "stable",
16 "require": { 16 "require": {
17 - "php": ">=5.6.0", 17 + "php": ">=7.0",
18 "yiisoft/yii2": "~2.0.14", 18 "yiisoft/yii2": "~2.0.14",
19 "yiisoft/yii2-bootstrap": "~2.0.0", 19 "yiisoft/yii2-bootstrap": "~2.0.0",
20 "yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0", 20 "yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0",
21 "yiisoft/yii2-queue": "~2.1", 21 "yiisoft/yii2-queue": "~2.1",
22 - "yiisoft/yii2-redis": "^2.0" 22 + "yiisoft/yii2-redis": "^2.0",
  23 + "ext-curl": "*",
  24 + "ext-json": "*"
23 }, 25 },
24 "require-dev": { 26 "require-dev": {
25 "yiisoft/yii2-debug": "~2.1.0", 27 "yiisoft/yii2-debug": "~2.1.0",
@@ -64,15 +64,11 @@ class OrderController extends Controller @@ -64,15 +64,11 @@ class OrderController extends Controller
64 { 64 {
65 $input = Yii::$app->request->post(); 65 $input = Yii::$app->request->post();
66 Helper::writeLog('Order','新建订单-接收参数:'.json_encode($input)); 66 Helper::writeLog('Order','新建订单-接收参数:'.json_encode($input));
67 - if($input['service_type'] == 0){//畅聊  
68 - $data = $this->OrderLogic->addChatOrder($input);  
69 - }elseif($input['service_type'] == 2){//转化底粉  
70 - $data = $this->OrderLogic->addBottomFansOrder($input);  
71 - }elseif($input['service_type'] == 3){//Facebook  
72 - $data = $this->OrderLogic->addFacebookOrder($input);  
73 - }else{ 67 + $data = $this->OrderLogic->handleAddOrder($input);
  68 + if (false === $data) {
74 Helper::show('暂不支持该服务类型','',201); 69 Helper::show('暂不支持该服务类型','',201);
75 } 70 }
  71 +
76 Helper::show('添加成功',$data); 72 Helper::show('添加成功',$data);
77 } 73 }
78 74
@@ -93,4 +89,4 @@ class OrderController extends Controller @@ -93,4 +89,4 @@ class OrderController extends Controller
93 $data = $this->OrderLogic->delOrderData($input); 89 $data = $this->OrderLogic->delOrderData($input);
94 Helper::show('删除成功',$data); 90 Helper::show('删除成功',$data);
95 } 91 }
96 -}  
  92 +}
  1 +<?php
  2 +/**
  3 + * @class BaseOrderStrategy
  4 + * @package app\logic
  5 + * @date 2021/05/20 14:11
  6 + */
  7 +
  8 +namespace app\logic;
  9 +
  10 +use app\common\Helper;
  11 +use app\dao\OrderDao;
  12 +
  13 +abstract class BaseOrderStrategy
  14 +{
  15 + /**
  16 + * @var OrderDao
  17 + */
  18 + public $orderDao;
  19 +
  20 + /**
  21 + * @var Helper
  22 + */
  23 + public $helper;
  24 +
  25 + /**
  26 + * BaseOrderStrategy constructor.
  27 + * @param OrderDao $orderDao
  28 + */
  29 + public function __construct(OrderDao $orderDao)
  30 + {
  31 + $this->orderDao = $orderDao;
  32 + $this->helper = new Helper();
  33 + }
  34 +
  35 + /**
  36 + * 策略执行方法
  37 + * @param $input
  38 + * @return mixed
  39 + */
  40 + abstract public function handle($input);
  41 +
  42 + /**
  43 + * 生成订单号
  44 + */
  45 + protected function genOrderID() {
  46 + //查询订单表大于今天的统计总数
  47 + $today = date('Y-m-d') . ' 00:00:00';
  48 + $where = ['and', "add_time >= '{$today}'"];
  49 + $count = $this->orderDao->getOrderCount($where);
  50 + $total = isset($count) ? $count : 0;
  51 + $code = sprintf('%s%s%s%s', substr(date('Y'), 2), date('dm'), $total + 1 + 126, date('s')); // 126是起始值
  52 + //查库是否存在
  53 + $where = ['and', "order_id = '{$code}'"];
  54 + $info = $this->orderDao->getOrderInfo($where);
  55 + if(empty($info)){
  56 + return $code;
  57 + }else{
  58 + return $this->genOrderID();
  59 + }
  60 + }
  61 +
  62 + /**
  63 + * 发送请求
  64 + * @param $url
  65 + * @param $data
  66 + * @param string $origin
  67 + * @return bool|string
  68 + */
  69 + protected function sendPost($url, $data , $origin = '') { // 模拟提交数据函数
  70 + $curl = curl_init(); // 启动一个CURL会话
  71 + curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
  72 + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
  73 + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在
  74 +// curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
  75 + if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
  76 + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
  77 + } curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
  78 + if(!empty($origin)){
  79 + $header=array(
  80 + "Accept: application/json",
  81 + "Content-Type: application/json;charset=utf-8",
  82 + "Origin: " . $origin,
  83 + );
  84 + curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
  85 + }
  86 + curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
  87 + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
  88 + curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
  89 + curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
  90 + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
  91 + $tmpInfo = curl_exec($curl); // 执行操作
  92 + if (curl_errno($curl)) {
  93 + echo 'Errno' . curl_error($curl);
  94 + }
  95 + curl_close($curl); // 关键CURL会话
  96 +
  97 + return $tmpInfo; // 返回数据
  98 + }
  99 +
  100 +
  101 + /**
  102 + * 生成密钥
  103 + */
  104 + protected function genOrderSecret() {
  105 + $secret = $this->createRandStr(10, '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ');
  106 + //获取订单秘钥,判断是否存在
  107 + $where = ['and',"order_secret = '{$secret}'"];
  108 + $order_info = $this->OrderDao->getOrderInfo($where);
  109 + if (empty($order_info)) {
  110 + return $secret;
  111 + } else {
  112 + // HACK
  113 + return $this->genOrderSecret();
  114 + }
  115 + }
  116 +
  117 + /**
  118 + * 随机字符串生成
  119 + * @param int $len 需要随机的长度,不要太长
  120 + * @param string $chars 随机生成字符串的范围
  121 + *
  122 + * @return string
  123 + */
  124 + protected function createRandStr($len, $chars = null) {
  125 + if (!$chars) {
  126 + $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  127 + }
  128 +
  129 + return substr(str_shuffle(str_repeat($chars, rand(5, 8))), 0, $len);
  130 + }
  131 +}
  1 +<?php
  2 +/**
  3 + * @class BottomFansStrategy
  4 + * @package app\logic
  5 + * @date 2021/05/20 14:21
  6 + */
  7 +
  8 +namespace app\logic;
  9 +
  10 +use \Yii;
  11 +use app\common\Helper;
  12 +
  13 +class BottomFansStrategy extends BaseOrderStrategy
  14 +{
  15 +
  16 + /**
  17 + * @param $input
  18 + * @return mixed
  19 + */
  20 + public function handle($input)
  21 + {
  22 + $this->bottomFansOrderValidator($input);//参数过滤器
  23 +
  24 + $uuid = $input['uuid'];
  25 +
  26 + // 处理一下时间
  27 + if(!empty($input['start_time'])){
  28 + $today_time = date('Y-m-d 00:00:00');
  29 + if (strtotime($input['start_time']) < $_SERVER['REQUEST_TIME'] && strtotime($input['start_time']) > strtotime($today_time)) {
  30 + $input['start_time'] = date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']);
  31 + }
  32 + }
  33 + if(empty($input['start_time']) || strtotime($input['start_time']) < $_SERVER['REQUEST_TIME']) Helper::show('开始时间未设置或少于当前时间','',201);
  34 + //获取uuid对应的手机号
  35 + $where = ['and', "uuid = '{$uuid}'"];
  36 + $account = $this->orderDao->getAccountInfo($where);
  37 + $mobile = $account['mobile'];
  38 + //生成入库数组
  39 + $order_data['order_id'] = $this->genOrderID();
  40 + $order_data['supplier_no'] = $input['supplier_no'];
  41 + $order_data['service_type'] = $input['service_type'];
  42 + $order_data['sex'] = $input['sex'];
  43 + $order_data['select_data'] = $input['select_data'];
  44 + $order_data['data_note'] = $input['data_note'];
  45 + $order_data['start_time'] = $input['start_time'];
  46 + $order_data['order_note'] = $input['order_note'];
  47 + $order_data['order_status'] = 10;
  48 + $order_data['mobile'] = $mobile;
  49 +
  50 + //坐席释放时间
  51 + $release_time = strtotime($input['staff_release_time']) - time();
  52 + // if($release_time < 86400 || $release_time > 2592000) Helper::show('席位释放时间需在1至30天内','',201);
  53 + $order_data['staff_release_time'] = strtotime($input['staff_release_time']);
  54 +
  55 + //订单聊天结束时间
  56 + $chat_time = strtotime($input['chat_end_fan_time']) - time();
  57 + $order_data['chat_end_fan_time'] = strtotime($input['chat_end_fan_time']);
  58 +
  59 + //判断是云控台还是云订单
  60 + if($input['system_type'] == 2){
  61 + //下单状态order_status=20接单用户UUID cloud_console_uuid = 自己
  62 + $order_data['order_status'] = 20;
  63 + $order_data['order_cloud_console_status'] = 20;
  64 + $order_data['cloud_console_uuid'] = $uuid;
  65 + }
  66 +
  67 + $distribution_ids = [];
  68 + //判断服务类型,0畅聊1导粉
  69 + //验证相关字段是否为空
  70 +
  71 + $staff_distribution = json_decode($input['staff_distribution'],true);
  72 + if(empty($staff_distribution)) Helper::show('坐席分配未设置','',201);
  73 + //检测坐席格式
  74 + $arr = json_decode($input['staff_distribution'],true);
  75 + foreach ($arr as $item) {
  76 + if(!isset($item['id']) || !isset($item['alias']) || !isset($item['username'])) Helper::show('坐席分配格式错误','',201);
  77 + $distribution_ids[] = $item['id'];
  78 + }
  79 + $url = Yii::$app->params['chat_url'];
  80 + //发送数据包到对应接口
  81 +
  82 + //发送post-》grouping
  83 + $data = ['uuid' => $uuid,'group_name' => '未分组','order_uunum' => $order_data['order_id'],'first' => 1];
  84 + $post = $this->sendPost($url.'grouping',$data);
  85 + Helper::writeLog('Order','订单分组:'.$post);
  86 + //循环发送group_name-》grouping
  87 + if(isset($input['is_group']) && $input['is_group'] == 1){
  88 + $arr = json_decode($input['group_name'],true);
  89 + foreach ($arr as $key => $value) {
  90 + $data = ['uuid' => $uuid,'group_name' => $value,'order_uunum' => $order_data['order_id'],'first' => 0];
  91 + $post = $this->sendPost($url.'grouping',$data);
  92 + Helper::writeLog('Order','订单分组循环:'.$post);
  93 + }
  94 + }
  95 +
  96 + //判断订单系统 开启素材库 1开启 0关闭(默认)
  97 + if(isset($input['is_material']) && $input['is_material'] == 1){
  98 + $arr = json_decode($input['material_group'],true);
  99 + foreach ($arr as $key => $value) {
  100 + //循环发送material_group-》addOrderMaterial
  101 + $data = ['uuid' => $uuid,'status' => $value['status'],'order_order_id' => $order_data['order_id'],'group_id' => $value['group_id']];
  102 + $data = json_encode($data);
  103 + $post = $this->sendPost($url.'addOrderMaterial',$data);
  104 + Helper::writeLog('Order','开启素材库:'.$post);
  105 + }
  106 + }
  107 +
  108 + //判断畅聊系统 开启快捷回复 1开启 0关闭(默认)
  109 + if(isset($input['is_quick_reply']) && $input['is_quick_reply'] == 1){
  110 + //发送数据-》addOrderQuickReply
  111 + $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'group_id' => $input['quick_reply_group']];
  112 + $data = json_encode($data);
  113 + $post = $this->sendPost($url.'addOrderQuickReply',$data);
  114 + Helper::writeLog('Order','快捷回复:'.$post);
  115 + }
  116 +
  117 + //判断订单系统 开启关键词回复 1开启 0关闭(默认)
  118 + if(isset($input['is_keyword']) && $input['is_keyword'] == 1){
  119 + //发送数据-》addOrderKeyword
  120 + $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'group_id' => $input['keyword_group']];
  121 + $data = json_encode($data);
  122 + $post = $this->sendPost($url.'addOrderKeyword',$data);
  123 + Helper::writeLog('Order','关键词回复:'.$post);
  124 + $order_data['keyword_begin_time'] = isset($input['keyword_begin_time'])?$input['keyword_begin_time']:'00:00';
  125 + $order_data['keyword_end_time'] = isset($input['keyword_end_time'])?$input['keyword_end_time']:'24:00';
  126 + }
  127 +
  128 + //判断订单系统 开启自动回复 1开启 0关闭(默认)
  129 + if(isset($input['is_auto_reply']) && $input['is_auto_reply']){
  130 + //发送数据包-》addOrderAutoreply
  131 + $data = ['uuid' => $uuid,'id' => $input['auto_reply_id'],'order_order_id' => $order_data['order_id']];
  132 + $data = json_encode($data);
  133 + $post = $this->sendPost($url.'addOrderAutoreply',$data);
  134 + Helper::writeLog('Order','自动回复:'.$post);
  135 + $order_data['autoreply_begin_time'] = isset($input['autoreply_begin_time'])?$input['autoreply_begin_time']:'00:00';
  136 + $order_data['autoreply_end_time'] = isset($input['autoreply_end_time'])?$input['autoreply_end_time']:'24:00';
  137 + }
  138 +
  139 + //判断选择验证语ID
  140 + if(isset($input['verifying_language_id'])){
  141 + $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'id' => $input['verifying_language_id']];
  142 + $data = json_encode($data);
  143 + $post = $this->sendPost($url.'addOrderVerifyingLanguage',$data);
  144 + Helper::writeLog('Order','验证语:'.$post);
  145 + }
  146 +
  147 + //判断是否拉群
  148 + if(isset($input['is_colony']) && $input['is_colony'] == 1){
  149 + $colony_data = json_decode($input['colony_data'],true);
  150 + if(empty($colony_data)) Helper::show('拉群配置不能为空','',201);
  151 + //组装数据包
  152 + $data = [];
  153 + $data['uuid'] = $uuid;
  154 + $data['order_id'] = $order_data['order_id'];
  155 + $data['open_add_chat_room'] = true;
  156 + $data['chat_room_mode'] = $colony_data['chat_room_mode'];
  157 + $data['small_into_chat_room_limit_num'] =
  158 + $colony_data['small_into_chat_room_limit_num'];
  159 + $data['small_invite_fans_wait_limit_num'] =
  160 + $colony_data['small_invite_fans_wait_limit_num'];
  161 + $data['start_invite_fans_into_chat_room_num'] =
  162 + $colony_data['start_invite_fans_into_chat_room_num'];
  163 + $data['quit_chat_room_time'] = $colony_data['quit_chat_room_time'];
  164 + $data['into_chat_room_interval'] = $colony_data['into_chat_room_interval'];
  165 + $data['end_invite_fans_into_chat_room_time'] = $colony_data['end_invite_fans_into_chat_room_time'];
  166 + $data['code_ids'] = $colony_data['code_ids'];
  167 + Helper::writeLog('Order','拉群请求参数:'.json_encode($data));
  168 + //请求存储拉群配置接口
  169 + $url = Yii::$app->params['cloud_url'] . 'chat_room/config/save_chat_room_config';
  170 + $post = $this->sendPost($url, json_encode($data) , Yii::$app->params['origin_cloud_add_fans']);
  171 + Helper::writeLog('Order','拉群:'.$post);
  172 + }
  173 +
  174 + //添加开关字段
  175 + $order_data['is_hide_moblie'] = $input['is_hide_moblie'];
  176 + $order_data['is_quick_reply'] = $input['is_quick_reply'];
  177 + $order_data['is_get_fan_nickname'] = $input['is_get_fan_nickname'];
  178 + $order_data['is_material'] = $input['is_material'];
  179 + $order_data['is_keyword'] = $input['is_keyword'];
  180 + $order_data['is_auto_reply'] = $input['is_auto_reply'];
  181 + $order_data['is_group'] = $input['is_group'];
  182 + $order_data['staff_distribution'] = $input['staff_distribution'];
  183 + $order_data['is_del_repeat'] = isset($input['is_del_repeat'])?$input['is_del_repeat']:0;
  184 +
  185 + $order_data['uuid'] = $uuid;
  186 +
  187 + // 食物链最上游的订单号
  188 + $order_data['top_order_id'] = $order_data['order_id'];
  189 + // 密钥
  190 + $order_data['order_secret'] = $this->genOrderSecret();
  191 +
  192 + $this->orderDao->addOrderData($order_data);
  193 +
  194 + $order_id = $order_data['order_id'];
  195 +
  196 + // 下单成功后的数据回写
  197 + $updata = ['is_distribution' => 1, 'is_distribution_chat' => 1, 'order_order_id' => $order_id,'is_hide_moblie' => $input['is_hide_moblie'], 'is_auto_reply' => $input['is_auto_reply'], 'is_auto_reply_chat' => $input['is_auto_reply'], 'is_keyword' => $input['is_keyword'], 'is_keyword_chat' => $input['is_keyword'], 'is_release' => 0];
  198 + $distribution_ids = implode(',',$distribution_ids);
  199 + if(!empty($distribution_ids)){
  200 + $where = "uuid = '{$uuid}' AND id IN ($distribution_ids)";
  201 + //更新nt_staff
  202 + $this->orderDao->editStaffData($where,$updata);
  203 + }
  204 +
  205 + //坐席释放时间,单位/天,0等于不限时
  206 + if($release_time > 0){
  207 + //投递延时任务
  208 + $task = [
  209 + 'type' => 1,
  210 + 'order_id' => $order_data['order_id'],
  211 + 'time' => strtotime(date('Y-m-d') . ' 09:30:00') + 86400,
  212 + ];
  213 + Yii::$app->order->delay($release_time)->push(new \app\jobs\Order($task));
  214 + }
  215 +
  216 + //聊天结束时间,大于十年则是无限,不投递任务
  217 + $month_time = 86400 * 365 * 10;
  218 + $month_date = $chat_time - time();
  219 + if($chat_time > 0 && $month_date < $month_time){
  220 + //投递延时任务
  221 + $task = [
  222 + 'type' => 2,
  223 + 'order_id' => $order_data['order_id'],
  224 + 'time' => strtotime($input['chat_end_fan_time']),
  225 + ];
  226 + Yii::$app->order->delay($chat_time)->push(new \app\jobs\Order($task));
  227 + }
  228 +
  229 + $res['order_id'] = $order_data['order_id'];
  230 + $res['order_secret'] = $order_data['order_secret'];
  231 +
  232 + return $res;
  233 + }
  234 +
  235 + /**
  236 + * 底粉订单数据验证器
  237 + * @param $input
  238 + * @return bool
  239 + */
  240 + protected function bottomFansOrderValidator($input){
  241 + $rule = [
  242 + 'system_type' => [],//服务类型,0畅聊1导粉
  243 + 'service_type' => ['int',0,0,1],//服务类型,0畅聊1导粉
  244 + 'data_note' => [],//数据备注
  245 + 'staff_distribution' => ['json_array',1],//畅聊订单必须,席位分配,用JSON传递,格式:[{"id":"坐席ID","alias":"坐席名称"},{第二组……}]
  246 + 'start_time' => ['date',1],//畅聊订单必须,开始时间,格式例如:2020-01-02 10:00:00
  247 + 'order_note' => [],//订单备注
  248 + 'speaking_groups' => ['int',1,0,0],//推名片时必须,话术组,0默认交友话术
  249 + 'circle_secret' => [],//推名片时必须,商圈密钥
  250 + 'is_hide_moblie' => ['int',1,0,1],//隐藏手机号1开启(默认) 0关闭
  251 + 'is_quick_reply' => ['int',1,0,1],//畅聊系统 开启快捷回复 1开启 0关闭(默认)
  252 + 'quick_reply_group' => ['string',1],//快捷回复分组逗号拼接只能选二级分组
  253 + 'is_get_fan_nickname' => ['int',1,0,1],//订单系统 获取粉丝昵称 1开启 0关闭(默认)
  254 + 'verifying_language_id' => ['string',1],//选择验证语ID
  255 + 'is_material' => ['int',1,0,1],//订单系统 开启素材库 1开启 0关闭(默认)
  256 + 'material_group' => ['json_array',1],//素材库分组,格式:[{"status":"1","group_id":"1,2"}]
  257 + 'is_keyword' => ['int',1,0,1],//订单系统 开启关键词回复 1开启 0关闭(默认)
  258 + 'keyword_group' => ['string',1],//关键词分组逗号拼接
  259 + 'is_auto_reply' => ['int',1,0,1],//订单系统 开启自动回复 1开启 0关闭(默认)
  260 + 'auto_reply_id' => ['int',1],//自动回复ID
  261 + 'is_group' => ['int',1,0,1],//订单系统 开启粉丝分组1开启 0关闭(默认)
  262 + 'group_name' => ['json',1],//订单分组,格式:[1,3]
  263 + 'keyword_begin_time' => ['string',1],//添加关键词开始时间字符串12:00
  264 + 'keyword_end_time' => ['string',1],//添加关键词结束时间字符串12:00
  265 + 'autoreply_begin_time' => ['string',1],//添加自动回复开始时间字符串12:00
  266 + 'autoreply_end_time' => ['string',1],//添加自动回复结束 时间字符串12:00
  267 + // 'staff_release_time' => ['date',0],//坐席释放时间 Y-m-d H:i:s
  268 + 'chat_end_fan_time' => ['date',0],//聊天结束时间 Y-m-d H:i:s
  269 + 'is_del_repeat' => ['int',1,0,1],//是否去重 1开启 0关闭(默认)
  270 + ];
  271 + return $this->helper->validator($input,$rule);
  272 + }
  273 +}
  1 +<?php
  2 +/**
  3 + * @class ChatOrderStrategy
  4 + * @package app\logic
  5 + * @date 2021/05/20 14:17
  6 + */
  7 +
  8 +namespace app\logic;
  9 +
  10 +use \Yii;
  11 +use app\common\Helper;
  12 +
  13 +class ChatOrderStrategy extends BaseOrderStrategy
  14 +{
  15 + /**
  16 + * @param $input
  17 + * @return mixed
  18 + */
  19 + public function handle($input)
  20 + {
  21 + $this->chatOrderValidator($input);//参数过滤器
  22 +
  23 + $uuid = $input['uuid'];
  24 +
  25 + // 处理一下时间
  26 + if(!empty($input['start_time'])){
  27 + $today_time = date('Y-m-d 00:00:00');
  28 + if (strtotime($input['start_time']) < $_SERVER['REQUEST_TIME'] && strtotime($input['start_time']) > strtotime($today_time)) {
  29 + $input['start_time'] = date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']);
  30 + }
  31 + }
  32 + if(empty($input['start_time']) || strtotime($input['start_time']) < $_SERVER['REQUEST_TIME']) Helper::show('开始时间未设置或少于当前时间','',201);
  33 + //获取uuid对应的手机号
  34 + $where = ['and', "uuid = '{$uuid}'"];
  35 + $account = $this->orderDao->getAccountInfo($where);
  36 + $mobile = $account['mobile'];
  37 + //生成入库数组
  38 + $order_data['order_id'] = $this->genOrderID();
  39 + $order_data['supplier_no'] = $input['supplier_no'];
  40 + $order_data['service_type'] = $input['service_type'];
  41 + $order_data['sex'] = $input['sex'];
  42 + $order_data['select_data'] = $input['select_data'];
  43 + $order_data['data_note'] = $input['data_note'];
  44 + $order_data['start_time'] = $input['start_time'];
  45 + $order_data['order_note'] = $input['order_note'];
  46 + $order_data['order_status'] = 10;
  47 + $order_data['mobile'] = $mobile;
  48 +
  49 + //坐席释放时间
  50 + $release_time = strtotime($input['staff_release_time']) - time();
  51 + // if($release_time < 86400 || $release_time > 2592000) Helper::show('席位释放时间需在1至30天内','',201);
  52 + $order_data['staff_release_time'] = strtotime($input['staff_release_time']);
  53 +
  54 + //订单聊天结束时间
  55 + $chat_time = strtotime($input['chat_end_fan_time']) - time();
  56 + $order_data['chat_end_fan_time'] = strtotime($input['chat_end_fan_time']);
  57 +
  58 + //判断是云控台还是云订单
  59 + if($input['system_type'] == 2){
  60 + //下单状态order_status=20接单用户UUID cloud_console_uuid = 自己
  61 + $order_data['order_status'] = 20;
  62 + $order_data['order_cloud_console_status'] = 20;
  63 + $order_data['cloud_console_uuid'] = $uuid;
  64 + }
  65 +
  66 + //判断数据选择,0随机1精准数据
  67 + if($input['select_data'] == 1){
  68 + if(empty($input['data_warehouse_id']) || empty($input['data_warehouse_detail'])) Helper::show('缺少data_warehouse_id或data_warehouse_detail','',201);
  69 + //获取目录名
  70 + $where = ['and',"uuid = '{$uuid}'","id = {$input['data_warehouse_id']}"];
  71 + $warehouse = $this->orderDao->getWarehouseInfo($where);
  72 + $order_data['data_warehouse_id'] = $input['data_warehouse_id'];
  73 + $order_data['data_warehouse_detail'] = $input['data_warehouse_detail'];
  74 + $order_data['data_warehouse_folder_name'] = $warehouse['folder_name'];
  75 + }
  76 + $distribution_ids = [];
  77 + //验证相关字段是否为空
  78 + if($input['target_total'] <= 0) Helper::show('总目标未设置','',201);
  79 +
  80 + $order_data['target_total'] = $input['target_total'];
  81 + $staff_distribution = json_decode($input['staff_distribution'],true);
  82 + if(empty($staff_distribution)) Helper::show('坐席分配未设置','',201);
  83 + //检测坐席格式
  84 + $arr = json_decode($input['staff_distribution'],true);
  85 + foreach ($arr as $item) {
  86 + if(!isset($item['id']) || !isset($item['alias']) || !isset($item['username'])) Helper::show('坐席分配格式错误','',201);
  87 + $distribution_ids[] = $item['id'];
  88 + }
  89 + $url = Yii::$app->params['chat_url'];
  90 + //发送数据包到对应接口
  91 +
  92 + //发送post-》grouping
  93 + $data = ['uuid' => $uuid,'group_name' => '未分组','order_uunum' => $order_data['order_id'],'first' => 1];
  94 + $post = $this->sendPost($url.'grouping',$data);
  95 + Helper::writeLog('Order','订单分组:'.$post);
  96 + //循环发送group_name-》grouping
  97 + if(isset($input['is_group']) && $input['is_group'] == 1){
  98 + $arr = json_decode($input['group_name'],true);
  99 + foreach ($arr as $key => $value) {
  100 + $data = ['uuid' => $uuid,'group_name' => $value,'order_uunum' => $order_data['order_id'],'first' => 0];
  101 + $post = $this->sendPost($url.'grouping',$data);
  102 + Helper::writeLog('Order','订单分组循环:'.$post);
  103 + }
  104 + }
  105 +
  106 + //判断订单系统 开启素材库 1开启 0关闭(默认)
  107 + if(isset($input['is_material']) && $input['is_material'] == 1){
  108 + $arr = json_decode($input['material_group'],true);
  109 + foreach ($arr as $key => $value) {
  110 + //循环发送material_group-》addOrderMaterial
  111 + $data = ['uuid' => $uuid,'status' => $value['status'],'order_order_id' => $order_data['order_id'],'group_id' => $value['group_id']];
  112 + $data = json_encode($data);
  113 + $post = $this->sendPost($url.'addOrderMaterial',$data);
  114 + Helper::writeLog('Order','开启素材库:'.$post);
  115 + }
  116 + }
  117 +
  118 + //判断畅聊系统 开启快捷回复 1开启 0关闭(默认)
  119 + if(isset($input['is_quick_reply']) && $input['is_quick_reply'] == 1){
  120 + //发送数据-》addOrderQuickReply
  121 + $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'group_id' => $input['quick_reply_group']];
  122 + $data = json_encode($data);
  123 + $post = $this->sendPost($url.'addOrderQuickReply',$data);
  124 + Helper::writeLog('Order','快捷回复:'.$post);
  125 + }
  126 +
  127 + //判断订单系统 开启关键词回复 1开启 0关闭(默认)
  128 + if(isset($input['is_keyword']) && $input['is_keyword'] == 1){
  129 + //发送数据-》addOrderKeyword
  130 + $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'group_id' => $input['keyword_group']];
  131 + $data = json_encode($data);
  132 + $post = $this->sendPost($url.'addOrderKeyword',$data);
  133 + Helper::writeLog('Order','关键词回复:'.$post);
  134 + $order_data['keyword_begin_time'] = isset($input['keyword_begin_time'])?$input['keyword_begin_time']:'00:00';
  135 + $order_data['keyword_end_time'] = isset($input['keyword_end_time'])?$input['keyword_end_time']:'24:00';
  136 + }
  137 +
  138 + //判断订单系统 开启自动回复 1开启 0关闭(默认)
  139 + if(isset($input['is_auto_reply']) && $input['is_auto_reply']){
  140 + //发送数据包-》addOrderAutoreply
  141 + $data = ['uuid' => $uuid,'id' => $input['auto_reply_id'],'order_order_id' => $order_data['order_id']];
  142 + $data = json_encode($data);
  143 + $post = $this->sendPost($url.'addOrderAutoreply',$data);
  144 + Helper::writeLog('Order','自动回复:'.$post);
  145 + $order_data['autoreply_begin_time'] = isset($input['autoreply_begin_time'])?$input['autoreply_begin_time']:'00:00';
  146 + $order_data['autoreply_end_time'] = isset($input['autoreply_end_time'])?$input['autoreply_end_time']:'24:00';
  147 + }
  148 +
  149 + //判断选择验证语ID
  150 + if(isset($input['verifying_language_id'])){
  151 + $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'id' => $input['verifying_language_id']];
  152 + $data = json_encode($data);
  153 + $post = $this->sendPost($url.'addOrderVerifyingLanguage',$data);
  154 + Helper::writeLog('Order','验证语:'.$post);
  155 + }
  156 +
  157 + //判断是否拉群
  158 + if(isset($input['is_colony']) && $input['is_colony'] == 1){
  159 + $colony_data = json_decode($input['colony_data'],true);
  160 + if(empty($colony_data)) Helper::show('拉群配置不能为空','',201);
  161 + //组装数据包
  162 + $data = [];
  163 + $data['uuid'] = $uuid;
  164 + $data['order_id'] = $order_data['order_id'];
  165 + $data['open_add_chat_room'] = true;
  166 + $data['chat_room_mode'] = $colony_data['chat_room_mode'];
  167 + $data['small_into_chat_room_limit_num'] =
  168 + $colony_data['small_into_chat_room_limit_num'];
  169 + $data['small_invite_fans_wait_limit_num'] =
  170 + $colony_data['small_invite_fans_wait_limit_num'];
  171 + $data['start_invite_fans_into_chat_room_num'] =
  172 + $colony_data['start_invite_fans_into_chat_room_num'];
  173 + $data['quit_chat_room_time'] = $colony_data['quit_chat_room_time'];
  174 + $data['into_chat_room_interval'] = $colony_data['into_chat_room_interval'];
  175 + $data['end_invite_fans_into_chat_room_time'] = $colony_data['end_invite_fans_into_chat_room_time'];
  176 + $data['code_ids'] = $colony_data['code_ids'];
  177 + Helper::writeLog('Order','拉群请求参数:'.json_encode($data));
  178 + //请求存储拉群配置接口
  179 + $url = Yii::$app->params['cloud_url'] . 'chat_room/config/save_chat_room_config';
  180 + $post = $this->sendPost($url, json_encode($data) , Yii::$app->params['origin_cloud_add_fans']);
  181 + Helper::writeLog('Order','拉群:'.$post);
  182 + }
  183 +
  184 + //添加开关字段
  185 + $order_data['is_hide_moblie'] = $input['is_hide_moblie'];
  186 + $order_data['is_quick_reply'] = $input['is_quick_reply'];
  187 + $order_data['is_get_fan_nickname'] = $input['is_get_fan_nickname'];
  188 + $order_data['is_material'] = $input['is_material'];
  189 + $order_data['is_keyword'] = $input['is_keyword'];
  190 + $order_data['is_auto_reply'] = $input['is_auto_reply'];
  191 + $order_data['is_group'] = $input['is_group'];
  192 + $order_data['staff_distribution'] = $input['staff_distribution'];
  193 +
  194 + $order_data['uuid'] = $uuid;
  195 +
  196 + // 食物链最上游的订单号
  197 + $order_data['top_order_id'] = $order_data['order_id'];
  198 + // 密钥
  199 + $order_data['order_secret'] = $this->genOrderSecret();
  200 +
  201 + $this->orderDao->addOrderData($order_data);
  202 +
  203 + $order_id = $order_data['order_id'];
  204 +
  205 + // 下单成功后的数据回写
  206 + $updata = ['is_distribution' => 1, 'is_distribution_chat' => 1, 'order_order_id' => $order_id,'is_hide_moblie' => $input['is_hide_moblie'], 'is_auto_reply' => $input['is_auto_reply'], 'is_auto_reply_chat' => $input['is_auto_reply'], 'is_keyword' => $input['is_keyword'], 'is_keyword_chat' => $input['is_keyword'], 'is_release' => 0];
  207 + $distribution_ids = implode(',',$distribution_ids);
  208 + if(!empty($distribution_ids)){
  209 + $where = "uuid = '{$uuid}' AND id IN ($distribution_ids)";
  210 + //更新nt_staff
  211 + $this->orderDao->editStaffData($where,$updata);
  212 + }
  213 +
  214 + //坐席释放时间,单位/天,0等于不限时
  215 + if($release_time > 0){
  216 + //投递延时任务
  217 + $task = [
  218 + 'type' => 1,
  219 + 'order_id' => $order_data['order_id'],
  220 + 'time' => strtotime(date('Y-m-d') . ' 09:30:00') + 86400,
  221 + ];
  222 + Yii::$app->order->delay($release_time)->push(new \app\jobs\Order($task));
  223 + }
  224 +
  225 + //聊天结束时间,大于十年则是无限,不投递任务
  226 + $month_time = 86400 * 365 * 10;
  227 + $month_date = $chat_time - time();
  228 + if($chat_time > 0 && $month_date < $month_time){
  229 + //投递延时任务
  230 + $task = [
  231 + 'type' => 2,
  232 + 'order_id' => $order_data['order_id'],
  233 + 'time' => strtotime($input['chat_end_fan_time']),
  234 + ];
  235 + Yii::$app->order->delay($chat_time)->push(new \app\jobs\Order($task));
  236 + }
  237 +
  238 + $res['order_id'] = $order_data['order_id'];
  239 + $res['order_secret'] = $order_data['order_secret'];
  240 +
  241 + return $res;
  242 + }
  243 +
  244 + /**
  245 + * 畅聊订单数据验证器
  246 + * @param $input
  247 + * @return bool
  248 + */
  249 + public function chatOrderValidator($input){
  250 + $rule = [
  251 + 'system_type' => [],//服务类型,0畅聊1导粉
  252 + 'service_type' => ['int',0,0,1],//服务类型,0畅聊1导粉
  253 + 'sex' => ['int',0,0,6],//推广粉丝,0不限1男2女3男女4男无5女无6性别未知
  254 + 'select_data' => ['int',0],//数据选择,0随机1精准数据
  255 + 'data_warehouse_id' => ['int',1],//精准数据必须,数据目录ID,传warehouse_id
  256 + 'data_warehouse_detail' => ['json',1],//选择数据的详情,用JSON传递,格式:{"left_amount":可用数量,"repeat_percent":"系统重复率"}
  257 + 'data_note' => [],//数据备注
  258 + 'staff_distribution' => ['json_array',1],//畅聊订单必须,席位分配,用JSON传递,格式:[{"id":"坐席ID","alias":"坐席名称"},{第二组……}]
  259 + 'target_total' => ['int',1],//畅聊订单必须,总目标
  260 + 'start_time' => ['date',1],//畅聊订单必须,开始时间,格式例如:2020-01-02 10:00:00
  261 + 'order_note' => [],//订单备注
  262 + 'speaking_groups' => ['int',1,0,0],//推名片时必须,话术组,0默认交友话术
  263 + 'circle_secret' => [],//推名片时必须,商圈密钥
  264 + 'personal_account_list' => ['json_array',1],//(待完善)推名片时必须,个人号信息列表,格式:[{"mainwxid":"WXID","nickname":"昵称","headImage":"头像","day_total":单日目标,"target_total":总目标}]
  265 + 'is_hide_moblie' => ['int',1,0,1],//隐藏手机号1开启(默认) 0关闭
  266 + 'is_quick_reply' => ['int',1,0,1],//畅聊系统 开启快捷回复 1开启 0关闭(默认)
  267 + 'quick_reply_group' => ['string',1],//快捷回复分组逗号拼接只能选二级分组
  268 + 'is_get_fan_nickname' => ['int',1,0,1],//订单系统 获取粉丝昵称 1开启 0关闭(默认)
  269 + 'verifying_language_id' => ['string',1],//选择验证语ID
  270 + 'is_material' => ['int',1,0,1],//订单系统 开启素材库 1开启 0关闭(默认)
  271 + 'material_group' => ['json_array',1],//素材库分组,格式:[{"status":"1","group_id":"1,2"}]
  272 + 'is_keyword' => ['int',1,0,1],//订单系统 开启关键词回复 1开启 0关闭(默认)
  273 + 'keyword_group' => ['string',1],//关键词分组逗号拼接
  274 + 'is_auto_reply' => ['int',1,0,1],//订单系统 开启自动回复 1开启 0关闭(默认)
  275 + 'auto_reply_id' => ['int',1],//自动回复ID
  276 + 'is_group' => ['int',1,0,1],//订单系统 开启粉丝分组1开启 0关闭(默认)
  277 + 'group_name' => ['json',1],//订单分组,格式:[1,3]
  278 + 'is_colony' => ['int',1],//拉群开关 1开启 0关闭(默认)
  279 + 'colony_data' => ['json',1],//拉群配置
  280 + 'keyword_begin_time' => ['string',1],//添加关键词开始时间字符串12:00
  281 + 'keyword_end_time' => ['string',1],//添加关键词结束时间字符串12:00
  282 + 'autoreply_begin_time' => ['string',1],//添加自动回复开始时间字符串12:00
  283 + 'autoreply_end_time' => ['string',1],//添加自动回复结束 时间字符串12:00
  284 + // 'staff_release_time' => ['date',0],//坐席释放时间 Y-m-d H:i:s
  285 + 'chat_end_fan_time' => ['date',0],//聊天结束时间 Y-m-d H:i:s
  286 + ];
  287 + return $this->helper->validator($input,$rule);
  288 + }
  289 +}
  1 +<?php
  2 +/**
  3 + * @class FacebookOrderStrategy
  4 + * @package app\logic
  5 + * @date 2021/05/20 14:24
  6 + */
  7 +
  8 +namespace app\logic;
  9 +
  10 +use \Yii;
  11 +use app\common\Helper;
  12 +
  13 +class FacebookOrderStrategy extends BaseOrderStrategy
  14 +{
  15 + /**
  16 + * @param $input
  17 + * @return mixed
  18 + */
  19 + public function handle($input)
  20 + {
  21 + // $this->facebookValidator($input);//参数过滤器
  22 + $uuid = $input['uuid'];
  23 + //获取uuid对应的手机号
  24 + $where = ['and', "uuid = '{$uuid}'"];
  25 + $account = $this->orderDao->getAccountInfo($where);
  26 + $mobile = $account['mobile'];
  27 +
  28 + //生成入库数组
  29 + $order_data['order_id'] = $this->genOrderID();
  30 + $order_data['service_type'] = $input['service_type'];
  31 + $order_data['sex'] = $input['sex'];
  32 + $order_data['select_data'] = $input['select_data'];
  33 + $order_data['data_note'] = $input['data_note'];
  34 + $order_data['start_time'] = $input['start_time'];
  35 + $order_data['order_note'] = $input['order_note'];
  36 + $order_data['order_status'] = 10;
  37 + $order_data['mobile'] = $mobile;
  38 + $order_data['target_countries'] = $input['target_countries'];
  39 +
  40 + //坐席释放时间
  41 + $release_time = strtotime($input['staff_release_time']) - time();
  42 + // if($release_time < 86400 || $release_time > 2592000) Helper::show('席位释放时间需在1至30天内','',201);
  43 + $order_data['staff_release_time'] = strtotime($input['staff_release_time']);
  44 +
  45 + //订单聊天结束时间
  46 + $chat_time = strtotime($input['chat_end_fan_time']) - time();
  47 + $order_data['chat_end_fan_time'] = strtotime($input['chat_end_fan_time']);
  48 +
  49 + //判断是云控台还是云订单
  50 + if($input['system_type'] == 2){
  51 + //下单状态order_status=20接单用户UUID cloud_console_uuid = 自己
  52 + $order_data['order_status'] = 20;
  53 + $order_data['order_cloud_console_status'] = 20;
  54 + $order_data['cloud_console_uuid'] = $uuid;
  55 + }
  56 + //判断数据选择,0随机1精准数据
  57 + if($input['select_data'] == 1){
  58 + if(empty($input['data_warehouse_id']) || empty($input['data_warehouse_detail'])) Helper::show('缺少data_warehouse_id或data_warehouse_detail','',201);
  59 + //获取目录名
  60 + $where = ['and',"uuid = '{$uuid}'","id = {$input['data_warehouse_id']}"];
  61 + $warehouse = $this->orderDao->getWarehouseInfo($where);
  62 + $order_data['data_warehouse_id'] = $input['data_warehouse_id'];
  63 + $order_data['data_warehouse_detail'] = $input['data_warehouse_detail'];
  64 + $order_data['data_warehouse_folder_name'] = $warehouse['folder_name'];
  65 + }
  66 + $distribution_ids = [];
  67 + //判断服务类型,0畅聊1导粉2转化底粉3脸书
  68 + //验证相关字段是否为空
  69 + $order_data['target_total'] = $input['target_total'];
  70 +
  71 + $staff_distribution = json_decode($input['staff_distribution'],true);
  72 + if(empty($staff_distribution)) Helper::show('坐席分配未设置','',201);
  73 + //检测坐席格式
  74 + $arr = json_decode($input['staff_distribution'],true);
  75 + foreach ($arr as $item) {
  76 + if(!isset($item['id']) || !isset($item['alias']) || !isset($item['username'])) Helper::show('坐席分配格式错误','',201);
  77 + $distribution_ids[] = $item['id'];
  78 + }
  79 + $url = Yii::$app->params['chat_url'];
  80 + //发送数据包到对应接口
  81 +
  82 + //发送post-》grouping
  83 + $data = ['uuid' => $uuid,'group_name' => '未分组','order_uunum' => $order_data['order_id'],'first' => 1];
  84 + $post = $this->sendPost($url.'grouping',$data);
  85 + Helper::writeLog('Order','订单分组:'.$post);
  86 + //循环发送group_name-》grouping
  87 + if(isset($input['is_group']) && $input['is_group'] == 1){
  88 + $arr = json_decode($input['group_name'],true);
  89 + foreach ($arr as $key => $value) {
  90 + $data = ['uuid' => $uuid,'group_name' => $value,'order_uunum' => $order_data['order_id'],'first' => 0];
  91 + $post = $this->sendPost($url.'grouping',$data);
  92 + Helper::writeLog('Order','订单分组循环:'.$post);
  93 + }
  94 + }
  95 +
  96 + //判断订单系统 开启素材库 1开启 0关闭(默认)
  97 + if(isset($input['is_material']) && $input['is_material'] == 1){
  98 + $arr = json_decode($input['material_group'],true);
  99 + foreach ($arr as $key => $value) {
  100 + //循环发送material_group-》addOrderMaterial
  101 + $data = ['uuid' => $uuid,'status' => $value['status'],'order_order_id' => $order_data['order_id'],'group_id' => $value['group_id']];
  102 + $data = json_encode($data);
  103 + $post = $this->sendPost($url.'addOrderMaterial',$data);
  104 + Helper::writeLog('Order','开启素材库:'.$post);
  105 + }
  106 + }
  107 +
  108 + //判断畅聊系统 开启快捷回复 1开启 0关闭(默认)
  109 + if(isset($input['is_quick_reply']) && $input['is_quick_reply'] == 1){
  110 + //发送数据-》addOrderQuickReply
  111 + $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'group_id' => $input['quick_reply_group']];
  112 + $data = json_encode($data);
  113 + $post = $this->sendPost($url.'addOrderQuickReply',$data);
  114 + Helper::writeLog('Order','快捷回复:'.$post);
  115 + }
  116 +
  117 + //判断订单系统 开启关键词回复 1开启 0关闭(默认)
  118 + if(isset($input['is_keyword']) && $input['is_keyword'] == 1){
  119 + //发送数据-》addOrderKeyword
  120 + $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'group_id' => $input['keyword_group']];
  121 + $data = json_encode($data);
  122 + $post = $this->sendPost($url.'addOrderKeyword',$data);
  123 + Helper::writeLog('Order','关键词回复:'.$post);
  124 + $order_data['keyword_begin_time'] = isset($input['keyword_begin_time'])?$input['keyword_begin_time']:'00:00';
  125 + $order_data['keyword_end_time'] = isset($input['keyword_end_time'])?$input['keyword_end_time']:'24:00';
  126 + }
  127 +
  128 + //判断订单系统 开启自动回复 1开启 0关闭(默认)
  129 + if(isset($input['is_auto_reply']) && $input['is_auto_reply']){
  130 + //发送数据包-》addOrderAutoreply
  131 + $data = ['uuid' => $uuid,'id' => $input['auto_reply_id'],'order_order_id' => $order_data['order_id']];
  132 + $data = json_encode($data);
  133 + $post = $this->sendPost($url.'addOrderAutoreply',$data);
  134 + Helper::writeLog('Order','自动回复:'.$post);
  135 + $order_data['autoreply_begin_time'] = isset($input['autoreply_begin_time'])?$input['autoreply_begin_time']:'00:00';
  136 + $order_data['autoreply_end_time'] = isset($input['autoreply_end_time'])?$input['autoreply_end_time']:'24:00';
  137 + }
  138 +
  139 + //判断选择验证语ID
  140 + if(isset($input['verifying_language_id'])){
  141 + $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'id' => $input['verifying_language_id']];
  142 + $data = json_encode($data);
  143 + $post = $this->sendPost($url.'addOrderVerifyingLanguage',$data);
  144 + Helper::writeLog('Order','验证语:'.$post);
  145 + }
  146 +
  147 + //添加开关字段
  148 + $order_data['is_hide_moblie'] = $input['is_hide_moblie'];
  149 + $order_data['is_quick_reply'] = $input['is_quick_reply'];
  150 + $order_data['is_get_fan_nickname'] = $input['is_get_fan_nickname'];
  151 + $order_data['is_material'] = $input['is_material'];
  152 + $order_data['is_keyword'] = $input['is_keyword'];
  153 + $order_data['is_auto_reply'] = $input['is_auto_reply'];
  154 + $order_data['is_group'] = $input['is_group'];
  155 + $order_data['staff_distribution'] = $input['staff_distribution'];
  156 +
  157 + // Helper::writeLog('Order','订单的is_hide_moblie:'.$input['is_hide_moblie']);
  158 +
  159 + $order_data['uuid'] = $uuid;
  160 +
  161 + // 食物链最上游的订单号
  162 + $order_data['top_order_id'] = $order_data['order_id'];
  163 + // 密钥
  164 + $order_data['order_secret'] = $this->genOrderSecret();
  165 +
  166 + $this->orderDao->addOrderData($order_data);
  167 +
  168 + $order_id = $order_data['order_id'];
  169 +
  170 + // 下单成功后的数据回写
  171 + $updata = ['is_distribution' => 1, 'is_distribution_chat' => 1, 'order_order_id' => $order_id,'is_hide_moblie' => $input['is_hide_moblie'], 'is_auto_reply' => $input['is_auto_reply'], 'is_auto_reply_chat' => $input['is_auto_reply'], 'is_keyword' => $input['is_keyword'], 'is_keyword_chat' => $input['is_keyword'], 'is_release' => 0];
  172 + Helper::writeLog('Order','订单的 updata:'.json_encode($updata));
  173 + $distribution_ids = implode(',',$distribution_ids);
  174 + Helper::writeLog('Order','订单的 distribution_ids:'.json_encode($distribution_ids));
  175 + if(!empty($distribution_ids)){
  176 + $where = "uuid = '{$uuid}' AND id IN ($distribution_ids)";
  177 + Helper::writeLog('Order','订单的 where:'.$where);
  178 + //更新nt_staff
  179 + $this->orderDao->editStaffData($where,$updata);
  180 + }
  181 +
  182 + //坐席释放时间,单位/天,0等于不限时
  183 + if($release_time > 0){
  184 + //投递延时任务
  185 + $task = [
  186 + 'type' => 1,
  187 + 'order_id' => $order_data['order_id'],
  188 + 'time' => strtotime(date('Y-m-d') . ' 09:30:00') + 86400,
  189 + ];
  190 + Yii::$app->order->delay($release_time)->push(new \app\jobs\Order($task));
  191 + }
  192 +
  193 + //聊天结束时间,大于十年则是无限,不投递任务
  194 + $month_time = 86400 * 365 * 10;
  195 + $month_date = $chat_time - time();
  196 + if($chat_time > 0 && $month_date < $month_time){
  197 + //投递延时任务
  198 + $task = [
  199 + 'type' => 2,
  200 + 'order_id' => $order_data['order_id'],
  201 + 'time' => strtotime($input['chat_end_fan_time']),
  202 + ];
  203 + Yii::$app->order->delay($chat_time)->push(new \app\jobs\Order($task));
  204 + }
  205 +
  206 + // push队列初始化分组
  207 + Yii::$app->order->push(new \app\jobs\Order([
  208 + 'type' => 3,
  209 + 'order_id' => $order_data['order_id']
  210 + ]));
  211 +
  212 + $res['order_id'] = $order_data['order_id'];
  213 + $res['order_secret'] = $order_data['order_secret'];
  214 +
  215 + return $res;
  216 + }
  217 +
  218 + /**
  219 + * facebook订单数据验证器
  220 + * @param $input
  221 + * @return bool
  222 + */
  223 + protected function facebookValidator($input){
  224 + $rule = [
  225 + 'system_type' => [],//服务类型,0畅聊1导粉
  226 + 'service_type' => ['int',0,0,1],//服务类型,0畅聊1导粉
  227 + 'sex' => ['int',0,0,6],//推广粉丝,0不限1男2女3男女4男无5女无6性别未知
  228 + 'staff_distribution' => ['json_array',1],//畅聊订单必须,席位分配,用JSON传递,格式:[{"id":"坐席ID","alias":"坐席名称"},{第二组……}]
  229 + 'target_total' => ['int',1],//畅聊订单必须,总目标
  230 + 'order_note' => [],//订单备注
  231 + 'speaking_groups' => ['int',1,0,0],//推名片时必须,话术组,0默认交友话术
  232 + 'circle_secret' => [],//推名片时必须,商圈密钥
  233 + 'personal_account_list' => ['json_array',1],//(待完善)推名片时必须,个人号信息列表,格式:[{"mainwxid":"WXID","nickname":"昵称","headImage":"头像","day_total":单日目标,"target_total":总目标}]
  234 + 'is_hide_moblie' => ['int',1,0,1],//隐藏手机号1开启(默认) 0关闭
  235 + 'is_quick_reply' => ['int',1,0,1],//畅聊系统 开启快捷回复 1开启 0关闭(默认)
  236 + 'quick_reply_group' => ['string',1],//快捷回复分组逗号拼接只能选二级分组
  237 + 'is_get_fan_nickname' => ['int',1,0,1],//订单系统 获取粉丝昵称 1开启 0关闭(默认)
  238 + 'verifying_language_id' => ['string',1],//选择验证语ID
  239 + 'is_material' => ['int',1,0,1],//订单系统 开启素材库 1开启 0关闭(默认)
  240 + 'material_group' => ['json_array',1],//素材库分组,格式:[{"status":"1","group_id":"1,2"}]
  241 + 'is_keyword' => ['int',1,0,1],//订单系统 开启关键词回复 1开启 0关闭(默认)
  242 + 'keyword_group' => ['string',1],//关键词分组逗号拼接
  243 + 'is_auto_reply' => ['int',1,0,1],//订单系统 开启自动回复 1开启 0关闭(默认)
  244 + 'auto_reply_id' => ['int',1],//自动回复ID
  245 + 'is_group' => ['int',1,0,1],//订单系统 开启粉丝分组1开启 0关闭(默认)
  246 + 'group_name' => ['json',1],//订单分组,格式:[1,3]
  247 + 'keyword_begin_time' => ['string',1],//添加关键词开始时间字符串12:00
  248 + 'keyword_end_time' => ['string',1],//添加关键词结束时间字符串12:00
  249 + 'autoreply_begin_time' => ['string',1],//添加自动回复开始时间字符串12:00
  250 + 'autoreply_end_time' => ['string',1],//添加自动回复结束 时间字符串12:00
  251 + // 'staff_release_time' => ['date',0],//坐席释放时间 Y-m-d H:i:s
  252 + 'chat_end_fan_time' => ['date',0],//聊天结束时间 Y-m-d H:i:s
  253 + 'target_countries' => ['string',0],//目标国家
  254 + ];
  255 + return $this->helper->validator($input,$rule);
  256 + }
  257 +}
1 <?php 1 <?php
2 namespace app\logic; 2 namespace app\logic;
3 3
4 -use Yii;  
5 use app\common\Helper; 4 use app\common\Helper;
6 use app\dao\OrderDao; 5 use app\dao\OrderDao;
7 6
8 class OrderLogic 7 class OrderLogic
9 { 8 {
  9 + /**
  10 + * OrderDao对象实例
  11 + * @var OrderDao
  12 + */
10 public $OrderDao; 13 public $OrderDao;
  14 +
  15 + /**
  16 + * Helper对象实例
  17 + * @var Helper
  18 + */
11 public $Helper; 19 public $Helper;
12 20
  21 + /**
  22 + * OrderLogic constructor.
  23 + * @param OrderDao $OrderDao
  24 + */
13 public function __construct(OrderDao $OrderDao) 25 public function __construct(OrderDao $OrderDao)
14 { 26 {
15 $this->Helper = new Helper(); 27 $this->Helper = new Helper();
16 $this->OrderDao = $OrderDao; 28 $this->OrderDao = $OrderDao;
17 } 29 }
18 30
  31 + /**
  32 + * 获取订单列表
  33 + * @param $input
  34 + * @return mixed
  35 + */
19 public function getOrderList($input){ 36 public function getOrderList($input){
20 $where[] = 'and'; 37 $where[] = 'and';
21 $where[] = ['or',"uuid = '{$input['uuid']}'","cloud_console_uuid = '{$input['uuid']}'"]; 38 $where[] = ['or',"uuid = '{$input['uuid']}'","cloud_console_uuid = '{$input['uuid']}'"];
@@ -62,6 +79,11 @@ class OrderLogic @@ -62,6 +79,11 @@ class OrderLogic
62 return $data; 79 return $data;
63 } 80 }
64 81
  82 + /**
  83 + * 获取订单信息
  84 + * @param $input
  85 + * @return array|\yii\db\ActiveRecord|null
  86 + */
65 public function getOrderInfo($input){ 87 public function getOrderInfo($input){
66 $where = ['and', "order_id = '{$input['order_id']}'"]; 88 $where = ['and', "order_id = '{$input['order_id']}'"];
67 $field = ["order_id","add_time","data_warehouse_id","data_warehouse_folder_name","staff_distribution","service_type","target_total","finish_total","order_status","order_note","data_note","start_time","speaking_groups","circle_secret","personal_account_list","sex","is_forward","order_secret","is_hide_moblie","is_quick_reply","is_get_fan_nickname","is_material","is_keyword","keyword_begin_time","keyword_end_time","is_auto_reply","autoreply_begin_time","autoreply_end_time","is_group",'chat_end_fan_time',"staff_release_time","is_del_repeat","target_countries"]; 89 $field = ["order_id","add_time","data_warehouse_id","data_warehouse_folder_name","staff_distribution","service_type","target_total","finish_total","order_status","order_note","data_note","start_time","speaking_groups","circle_secret","personal_account_list","sex","is_forward","order_secret","is_hide_moblie","is_quick_reply","is_get_fan_nickname","is_material","is_keyword","keyword_begin_time","keyword_end_time","is_auto_reply","autoreply_begin_time","autoreply_end_time","is_group",'chat_end_fan_time',"staff_release_time","is_del_repeat","target_countries"];
@@ -94,782 +116,62 @@ class OrderLogic @@ -94,782 +116,62 @@ class OrderLogic
94 return $data; 116 return $data;
95 } 117 }
96 118
  119 + /**
  120 + * 编辑订单数据
  121 + * @param $input
  122 + * @return int
  123 + */
97 public function editOrderData($input){ 124 public function editOrderData($input){
98 $where = ['and', "id = {$input['id']}"]; 125 $where = ['and', "id = {$input['id']}"];
99 unset($input['id']); 126 unset($input['id']);
100 return $this->OrderDao->editOrderData($where,$input); 127 return $this->OrderDao->editOrderData($where,$input);
101 } 128 }
102 129
  130 + /**
  131 + * 编辑订单隐藏手机号码
  132 + * @param $input
  133 + * @return int
  134 + */
103 public function editOrderHideMoblie($input){ 135 public function editOrderHideMoblie($input){
104 $where = "order_id = '{$input['order_id']}' AND uuid = '{$input['uuid']}'"; 136 $where = "order_id = '{$input['order_id']}' AND uuid = '{$input['uuid']}'";
105 $data['is_hide_moblie'] = $input['on_off']; 137 $data['is_hide_moblie'] = $input['on_off'];
106 return $this->OrderDao->editOrderData($where,$data); 138 return $this->OrderDao->editOrderData($where,$data);
107 } 139 }
108 140
109 - public function chatOrderValidator($input){  
110 - $rule = [  
111 - 'system_type' => [],//服务类型,0畅聊1导粉  
112 - 'service_type' => ['int',0,0,1],//服务类型,0畅聊1导粉  
113 - 'sex' => ['int',0,0,6],//推广粉丝,0不限1男2女3男女4男无5女无6性别未知  
114 - 'select_data' => ['int',0],//数据选择,0随机1精准数据  
115 - 'data_warehouse_id' => ['int',1],//精准数据必须,数据目录ID,传warehouse_id  
116 - 'data_warehouse_detail' => ['json',1],//选择数据的详情,用JSON传递,格式:{"left_amount":可用数量,"repeat_percent":"系统重复率"}  
117 - 'data_note' => [],//数据备注  
118 - 'staff_distribution' => ['json_array',1],//畅聊订单必须,席位分配,用JSON传递,格式:[{"id":"坐席ID","alias":"坐席名称"},{第二组……}]  
119 - 'target_total' => ['int',1],//畅聊订单必须,总目标  
120 - 'start_time' => ['date',1],//畅聊订单必须,开始时间,格式例如:2020-01-02 10:00:00  
121 - 'order_note' => [],//订单备注  
122 - 'speaking_groups' => ['int',1,0,0],//推名片时必须,话术组,0默认交友话术  
123 - 'circle_secret' => [],//推名片时必须,商圈密钥  
124 - 'personal_account_list' => ['json_array',1],//(待完善)推名片时必须,个人号信息列表,格式:[{"mainwxid":"WXID","nickname":"昵称","headImage":"头像","day_total":单日目标,"target_total":总目标}]  
125 - 'is_hide_moblie' => ['int',1,0,1],//隐藏手机号1开启(默认) 0关闭  
126 - 'is_quick_reply' => ['int',1,0,1],//畅聊系统 开启快捷回复 1开启 0关闭(默认)  
127 - 'quick_reply_group' => ['string',1],//快捷回复分组逗号拼接只能选二级分组  
128 - 'is_get_fan_nickname' => ['int',1,0,1],//订单系统 获取粉丝昵称 1开启 0关闭(默认)  
129 - 'verifying_language_id' => ['string',1],//选择验证语ID  
130 - 'is_material' => ['int',1,0,1],//订单系统 开启素材库 1开启 0关闭(默认)  
131 - 'material_group' => ['json_array',1],//素材库分组,格式:[{"status":"1","group_id":"1,2"}]  
132 - 'is_keyword' => ['int',1,0,1],//订单系统 开启关键词回复 1开启 0关闭(默认)  
133 - 'keyword_group' => ['string',1],//关键词分组逗号拼接  
134 - 'is_auto_reply' => ['int',1,0,1],//订单系统 开启自动回复 1开启 0关闭(默认)  
135 - 'auto_reply_id' => ['int',1],//自动回复ID  
136 - 'is_group' => ['int',1,0,1],//订单系统 开启粉丝分组1开启 0关闭(默认)  
137 - 'group_name' => ['json',1],//订单分组,格式:[1,3]  
138 - 'is_colony' => ['int',1],//拉群开关 1开启 0关闭(默认)  
139 - 'colony_data' => ['json',1],//拉群配置  
140 - 'keyword_begin_time' => ['string',1],//添加关键词开始时间字符串12:00  
141 - 'keyword_end_time' => ['string',1],//添加关键词结束时间字符串12:00  
142 - 'autoreply_begin_time' => ['string',1],//添加自动回复开始时间字符串12:00  
143 - 'autoreply_end_time' => ['string',1],//添加自动回复结束 时间字符串12:00  
144 - // 'staff_release_time' => ['date',0],//坐席释放时间 Y-m-d H:i:s  
145 - 'chat_end_fan_time' => ['date',0],//聊天结束时间 Y-m-d H:i:s  
146 - ];  
147 - return $this->Helper->validator($input,$rule);  
148 - }  
149 -  
150 - public function bottomFansOrderValidator($input){  
151 - $rule = [  
152 - 'system_type' => [],//服务类型,0畅聊1导粉  
153 - 'service_type' => ['int',0,0,1],//服务类型,0畅聊1导粉  
154 - 'data_note' => [],//数据备注  
155 - 'staff_distribution' => ['json_array',1],//畅聊订单必须,席位分配,用JSON传递,格式:[{"id":"坐席ID","alias":"坐席名称"},{第二组……}]  
156 - 'start_time' => ['date',1],//畅聊订单必须,开始时间,格式例如:2020-01-02 10:00:00  
157 - 'order_note' => [],//订单备注  
158 - 'speaking_groups' => ['int',1,0,0],//推名片时必须,话术组,0默认交友话术  
159 - 'circle_secret' => [],//推名片时必须,商圈密钥  
160 - 'is_hide_moblie' => ['int',1,0,1],//隐藏手机号1开启(默认) 0关闭  
161 - 'is_quick_reply' => ['int',1,0,1],//畅聊系统 开启快捷回复 1开启 0关闭(默认)  
162 - 'quick_reply_group' => ['string',1],//快捷回复分组逗号拼接只能选二级分组  
163 - 'is_get_fan_nickname' => ['int',1,0,1],//订单系统 获取粉丝昵称 1开启 0关闭(默认)  
164 - 'verifying_language_id' => ['string',1],//选择验证语ID  
165 - 'is_material' => ['int',1,0,1],//订单系统 开启素材库 1开启 0关闭(默认)  
166 - 'material_group' => ['json_array',1],//素材库分组,格式:[{"status":"1","group_id":"1,2"}]  
167 - 'is_keyword' => ['int',1,0,1],//订单系统 开启关键词回复 1开启 0关闭(默认)  
168 - 'keyword_group' => ['string',1],//关键词分组逗号拼接  
169 - 'is_auto_reply' => ['int',1,0,1],//订单系统 开启自动回复 1开启 0关闭(默认)  
170 - 'auto_reply_id' => ['int',1],//自动回复ID  
171 - 'is_group' => ['int',1,0,1],//订单系统 开启粉丝分组1开启 0关闭(默认)  
172 - 'group_name' => ['json',1],//订单分组,格式:[1,3]  
173 - 'keyword_begin_time' => ['string',1],//添加关键词开始时间字符串12:00  
174 - 'keyword_end_time' => ['string',1],//添加关键词结束时间字符串12:00  
175 - 'autoreply_begin_time' => ['string',1],//添加自动回复开始时间字符串12:00  
176 - 'autoreply_end_time' => ['string',1],//添加自动回复结束 时间字符串12:00  
177 - // 'staff_release_time' => ['date',0],//坐席释放时间 Y-m-d H:i:s  
178 - 'chat_end_fan_time' => ['date',0],//聊天结束时间 Y-m-d H:i:s  
179 - 'is_del_repeat' => ['int',1,0,1],//是否去重 1开启 0关闭(默认)  
180 - ];  
181 - return $this->Helper->validator($input,$rule);  
182 - }  
183 -  
184 - public function facebookValidator($input){  
185 - $rule = [  
186 - 'system_type' => [],//服务类型,0畅聊1导粉  
187 - 'service_type' => ['int',0,0,1],//服务类型,0畅聊1导粉  
188 - 'sex' => ['int',0,0,6],//推广粉丝,0不限1男2女3男女4男无5女无6性别未知  
189 - 'staff_distribution' => ['json_array',1],//畅聊订单必须,席位分配,用JSON传递,格式:[{"id":"坐席ID","alias":"坐席名称"},{第二组……}]  
190 - 'target_total' => ['int',1],//畅聊订单必须,总目标  
191 - 'order_note' => [],//订单备注  
192 - 'speaking_groups' => ['int',1,0,0],//推名片时必须,话术组,0默认交友话术  
193 - 'circle_secret' => [],//推名片时必须,商圈密钥  
194 - 'personal_account_list' => ['json_array',1],//(待完善)推名片时必须,个人号信息列表,格式:[{"mainwxid":"WXID","nickname":"昵称","headImage":"头像","day_total":单日目标,"target_total":总目标}]  
195 - 'is_hide_moblie' => ['int',1,0,1],//隐藏手机号1开启(默认) 0关闭  
196 - 'is_quick_reply' => ['int',1,0,1],//畅聊系统 开启快捷回复 1开启 0关闭(默认)  
197 - 'quick_reply_group' => ['string',1],//快捷回复分组逗号拼接只能选二级分组  
198 - 'is_get_fan_nickname' => ['int',1,0,1],//订单系统 获取粉丝昵称 1开启 0关闭(默认)  
199 - 'verifying_language_id' => ['string',1],//选择验证语ID  
200 - 'is_material' => ['int',1,0,1],//订单系统 开启素材库 1开启 0关闭(默认)  
201 - 'material_group' => ['json_array',1],//素材库分组,格式:[{"status":"1","group_id":"1,2"}]  
202 - 'is_keyword' => ['int',1,0,1],//订单系统 开启关键词回复 1开启 0关闭(默认)  
203 - 'keyword_group' => ['string',1],//关键词分组逗号拼接  
204 - 'is_auto_reply' => ['int',1,0,1],//订单系统 开启自动回复 1开启 0关闭(默认)  
205 - 'auto_reply_id' => ['int',1],//自动回复ID  
206 - 'is_group' => ['int',1,0,1],//订单系统 开启粉丝分组1开启 0关闭(默认)  
207 - 'group_name' => ['json',1],//订单分组,格式:[1,3]  
208 - 'keyword_begin_time' => ['string',1],//添加关键词开始时间字符串12:00  
209 - 'keyword_end_time' => ['string',1],//添加关键词结束时间字符串12:00  
210 - 'autoreply_begin_time' => ['string',1],//添加自动回复开始时间字符串12:00  
211 - 'autoreply_end_time' => ['string',1],//添加自动回复结束 时间字符串12:00  
212 - // 'staff_release_time' => ['date',0],//坐席释放时间 Y-m-d H:i:s  
213 - 'chat_end_fan_time' => ['date',0],//聊天结束时间 Y-m-d H:i:s  
214 - 'target_countries' => ['string',0],//目标国家  
215 - ];  
216 - return $this->Helper->validator($input,$rule);  
217 - }  
218 -  
219 - public function addChatOrder($input){  
220 - $this->chatOrderValidator($input);//参数过滤器  
221 -  
222 - $uuid = $input['uuid'];  
223 -  
224 - // 处理一下时间  
225 - if(!empty($input['start_time'])){  
226 - $today_time = date('Y-m-d 00:00:00');  
227 - if (strtotime($input['start_time']) < $_SERVER['REQUEST_TIME'] && strtotime($input['start_time']) > strtotime($today_time)) {  
228 - $input['start_time'] = date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']);  
229 - }  
230 - }  
231 - if(empty($input['start_time']) || strtotime($input['start_time']) < $_SERVER['REQUEST_TIME']) Helper::show('开始时间未设置或少于当前时间','',201);  
232 - //获取uuid对应的手机号  
233 - $where = ['and', "uuid = '{$uuid}'"];  
234 - $account = $this->OrderDao->getAccountInfo($where);  
235 - $mobile = $account['mobile'];  
236 - //生成入库数组  
237 - $order_data['order_id'] = $this->genOrderID();  
238 - $order_data['supplier_no'] = $input['supplier_no'];  
239 - $order_data['service_type'] = $input['service_type'];  
240 - $order_data['sex'] = $input['sex'];  
241 - $order_data['select_data'] = $input['select_data'];  
242 - $order_data['data_note'] = $input['data_note'];  
243 - $order_data['start_time'] = $input['start_time'];  
244 - $order_data['order_note'] = $input['order_note'];  
245 - $order_data['order_status'] = 10;  
246 - $order_data['mobile'] = $mobile;  
247 -  
248 - //坐席释放时间  
249 - $release_time = strtotime($input['staff_release_time']) - time();  
250 - // if($release_time < 86400 || $release_time > 2592000) Helper::show('席位释放时间需在1至30天内','',201);  
251 - $order_data['staff_release_time'] = strtotime($input['staff_release_time']);  
252 -  
253 - //订单聊天结束时间  
254 - $chat_time = strtotime($input['chat_end_fan_time']) - time();  
255 - $order_data['chat_end_fan_time'] = strtotime($input['chat_end_fan_time']);  
256 -  
257 - //判断是云控台还是云订单  
258 - if($input['system_type'] == 2){  
259 - //下单状态order_status=20接单用户UUID cloud_console_uuid = 自己  
260 - $order_data['order_status'] = 20;  
261 - $order_data['order_cloud_console_status'] = 20;  
262 - $order_data['cloud_console_uuid'] = $uuid;  
263 - }  
264 -  
265 - //判断数据选择,0随机1精准数据  
266 - if($input['select_data'] == 1){  
267 - if(empty($input['data_warehouse_id']) || empty($input['data_warehouse_detail'])) Helper::show('缺少data_warehouse_id或data_warehouse_detail','',201);  
268 - //获取目录名  
269 - $where = ['and',"uuid = '{$uuid}'","id = {$input['data_warehouse_id']}"];  
270 - $warehouse = $this->OrderDao->getWarehouseInfo($where);  
271 - $order_data['data_warehouse_id'] = $input['data_warehouse_id'];  
272 - $order_data['data_warehouse_detail'] = $input['data_warehouse_detail'];  
273 - $order_data['data_warehouse_folder_name'] = $warehouse['folder_name'];  
274 - }  
275 - $distribution_ids = [];  
276 - //判断服务类型,0畅聊1导粉  
277 - if($input['service_type'] == 0){// 畅聊订单  
278 - //验证相关字段是否为空  
279 - if($input['target_total'] <= 0) Helper::show('总目标未设置','',201);  
280 -  
281 - $order_data['target_total'] = $input['target_total'];  
282 - $staff_distribution = json_decode($input['staff_distribution'],true);  
283 - if(empty($staff_distribution)) Helper::show('坐席分配未设置','',201);  
284 - //检测坐席格式  
285 - $arr = json_decode($input['staff_distribution'],true);  
286 - foreach ($arr as $item) {  
287 - if(!isset($item['id']) || !isset($item['alias']) || !isset($item['username'])) Helper::show('坐席分配格式错误','',201);  
288 - $distribution_ids[] = $item['id'];  
289 - }  
290 - $url = Yii::$app->params['chat_url'];  
291 - //发送数据包到对应接口  
292 -  
293 - //发送post-》grouping  
294 - $data = ['uuid' => $uuid,'group_name' => '未分组','order_uunum' => $order_data['order_id'],'first' => 1];  
295 - $post = $this->sendPost($url.'grouping',$data);  
296 - Helper::writeLog('Order','订单分组:'.$post);  
297 - //循环发送group_name-》grouping  
298 - if(isset($input['is_group']) && $input['is_group'] == 1){  
299 - $arr = json_decode($input['group_name'],true);  
300 - foreach ($arr as $key => $value) {  
301 - $data = ['uuid' => $uuid,'group_name' => $value,'order_uunum' => $order_data['order_id'],'first' => 0];  
302 - $post = $this->sendPost($url.'grouping',$data);  
303 - Helper::writeLog('Order','订单分组循环:'.$post);  
304 - }  
305 - }  
306 -  
307 - //判断订单系统 开启素材库 1开启 0关闭(默认)  
308 - if(isset($input['is_material']) && $input['is_material'] == 1){  
309 - $arr = json_decode($input['material_group'],true);  
310 - foreach ($arr as $key => $value) {  
311 - //循环发送material_group-》addOrderMaterial  
312 - $data = ['uuid' => $uuid,'status' => $value['status'],'order_order_id' => $order_data['order_id'],'group_id' => $value['group_id']];  
313 - $data = json_encode($data);  
314 - $post = $this->sendPost($url.'addOrderMaterial',$data);  
315 - Helper::writeLog('Order','开启素材库:'.$post);  
316 - }  
317 - }  
318 -  
319 - //判断畅聊系统 开启快捷回复 1开启 0关闭(默认)  
320 - if(isset($input['is_quick_reply']) && $input['is_quick_reply'] == 1){  
321 - //发送数据-》addOrderQuickReply  
322 - $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'group_id' => $input['quick_reply_group']];  
323 - $data = json_encode($data);  
324 - $post = $this->sendPost($url.'addOrderQuickReply',$data);  
325 - Helper::writeLog('Order','快捷回复:'.$post);  
326 - }  
327 -  
328 - //判断订单系统 开启关键词回复 1开启 0关闭(默认)  
329 - if(isset($input['is_keyword']) && $input['is_keyword'] == 1){  
330 - //发送数据-》addOrderKeyword  
331 - $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'group_id' => $input['keyword_group']];  
332 - $data = json_encode($data);  
333 - $post = $this->sendPost($url.'addOrderKeyword',$data);  
334 - Helper::writeLog('Order','关键词回复:'.$post);  
335 - $order_data['keyword_begin_time'] = isset($input['keyword_begin_time'])?$input['keyword_begin_time']:'00:00';  
336 - $order_data['keyword_end_time'] = isset($input['keyword_end_time'])?$input['keyword_end_time']:'24:00';  
337 - }  
338 -  
339 - //判断订单系统 开启自动回复 1开启 0关闭(默认)  
340 - if(isset($input['is_auto_reply']) && $input['is_auto_reply']){  
341 - //发送数据包-》addOrderAutoreply  
342 - $data = ['uuid' => $uuid,'id' => $input['auto_reply_id'],'order_order_id' => $order_data['order_id']];  
343 - $data = json_encode($data);  
344 - $post = $this->sendPost($url.'addOrderAutoreply',$data);  
345 - Helper::writeLog('Order','自动回复:'.$post);  
346 - $order_data['autoreply_begin_time'] = isset($input['autoreply_begin_time'])?$input['autoreply_begin_time']:'00:00';  
347 - $order_data['autoreply_end_time'] = isset($input['autoreply_end_time'])?$input['autoreply_end_time']:'24:00';  
348 - }  
349 -  
350 - //判断选择验证语ID  
351 - if(isset($input['verifying_language_id'])){  
352 - $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'id' => $input['verifying_language_id']];  
353 - $data = json_encode($data);  
354 - $post = $this->sendPost($url.'addOrderVerifyingLanguage',$data);  
355 - Helper::writeLog('Order','验证语:'.$post);  
356 - }  
357 -  
358 - //判断是否拉群  
359 - if(isset($input['is_colony']) && $input['is_colony'] == 1){  
360 - $colony_data = json_decode($input['colony_data'],true);  
361 - if(empty($colony_data)) Helper::show('拉群配置不能为空','',201);  
362 - //组装数据包  
363 - $data = [];  
364 - $data['uuid'] = $uuid;  
365 - $data['order_id'] = $order_data['order_id'];  
366 - $data['open_add_chat_room'] = true;  
367 - $data['chat_room_mode'] = $colony_data['chat_room_mode'];  
368 - $data['small_into_chat_room_limit_num'] =  
369 - $colony_data['small_into_chat_room_limit_num'];  
370 - $data['small_invite_fans_wait_limit_num'] =  
371 - $colony_data['small_invite_fans_wait_limit_num'];  
372 - $data['start_invite_fans_into_chat_room_num'] =  
373 - $colony_data['start_invite_fans_into_chat_room_num'];  
374 - $data['quit_chat_room_time'] = $colony_data['quit_chat_room_time'];  
375 - $data['into_chat_room_interval'] = $colony_data['into_chat_room_interval'];  
376 - $data['end_invite_fans_into_chat_room_time'] = $colony_data['end_invite_fans_into_chat_room_time'];  
377 - $data['code_ids'] = $colony_data['code_ids'];  
378 - Helper::writeLog('Order','拉群请求参数:'.json_encode($data));  
379 - //请求存储拉群配置接口  
380 - $url = Yii::$app->params['cloud_url'] . 'chat_room/config/save_chat_room_config';  
381 - $post = $this->sendPost($url, json_encode($data) , Yii::$app->params['origin_cloud_add_fans']);  
382 - Helper::writeLog('Order','拉群:'.$post);  
383 - }  
384 -  
385 - //添加开关字段  
386 - $order_data['is_hide_moblie'] = $input['is_hide_moblie'];  
387 - $order_data['is_quick_reply'] = $input['is_quick_reply'];  
388 - $order_data['is_get_fan_nickname'] = $input['is_get_fan_nickname'];  
389 - $order_data['is_material'] = $input['is_material'];  
390 - $order_data['is_keyword'] = $input['is_keyword'];  
391 - $order_data['is_auto_reply'] = $input['is_auto_reply'];  
392 - $order_data['is_group'] = $input['is_group'];  
393 - $order_data['staff_distribution'] = $input['staff_distribution'];  
394 -  
395 - }else{// 导粉订单  
396 - //先提升暂只支持畅聊订单  
397 - Helper::show('暂只支持畅聊订单','',201);  
398 - //判断商圈秘钥是否存在  
399 -  
400 - //判断人号信息是否设置  
401 -  
402 - //计数总目标personal_account_list-》target_total  
403 - }  
404 -  
405 - $order_data['uuid'] = $uuid;  
406 -  
407 - // 食物链最上游的订单号  
408 - $order_data['top_order_id'] = $order_data['order_id'];  
409 - // 密钥  
410 - $order_data['order_secret'] = $this->genOrderSecret();  
411 -  
412 - $this->OrderDao->addOrderData($order_data);  
413 -  
414 - $order_id = $order_data['order_id'];  
415 -  
416 - // 下单成功后的数据回写  
417 - $updata = ['is_distribution' => 1, 'is_distribution_chat' => 1, 'order_order_id' => $order_id,'is_hide_moblie' => $input['is_hide_moblie'], 'is_auto_reply' => $input['is_auto_reply'], 'is_auto_reply_chat' => $input['is_auto_reply'], 'is_keyword' => $input['is_keyword'], 'is_keyword_chat' => $input['is_keyword'], 'is_release' => 0];  
418 - $distribution_ids = implode(',',$distribution_ids);  
419 - if(!empty($distribution_ids)){  
420 - $where = "uuid = '{$uuid}' AND id IN ($distribution_ids)";  
421 - //更新nt_staff  
422 - $this->OrderDao->editStaffData($where,$updata);  
423 - }  
424 -  
425 - //坐席释放时间,单位/天,0等于不限时  
426 - if($release_time > 0){  
427 - //投递延时任务  
428 - $task = [  
429 - 'type' => 1,  
430 - 'order_id' => $order_data['order_id'],  
431 - 'time' => strtotime(date('Y-m-d') . ' 09:30:00') + 86400,  
432 - ];  
433 - Yii::$app->order->delay($release_time)->push(new \app\jobs\Order($task));  
434 - }  
435 -  
436 - //聊天结束时间,大于十年则是无限,不投递任务  
437 - $month_time = 86400 * 365 * 10;  
438 - $month_date = $chat_time - time();  
439 - if($chat_time > 0 && $month_date < $month_time){  
440 - //投递延时任务  
441 - $task = [  
442 - 'type' => 2,  
443 - 'order_id' => $order_data['order_id'],  
444 - 'time' => strtotime($input['chat_end_fan_time']),  
445 - ];  
446 - Yii::$app->order->delay($chat_time)->push(new \app\jobs\Order($task));  
447 - }  
448 -  
449 - $res['order_id'] = $order_data['order_id'];  
450 - $res['order_secret'] = $order_data['order_secret'];  
451 -  
452 - return $res;  
453 - }  
454 -  
455 - public function addBottomFansOrder($input){  
456 - $this->bottomFansOrderValidator($input);//参数过滤器  
457 -  
458 - $uuid = $input['uuid'];  
459 -  
460 - // 处理一下时间  
461 - if(!empty($input['start_time'])){  
462 - $today_time = date('Y-m-d 00:00:00');  
463 - if (strtotime($input['start_time']) < $_SERVER['REQUEST_TIME'] && strtotime($input['start_time']) > strtotime($today_time)) {  
464 - $input['start_time'] = date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']);  
465 - }  
466 - }  
467 - if(empty($input['start_time']) || strtotime($input['start_time']) < $_SERVER['REQUEST_TIME']) Helper::show('开始时间未设置或少于当前时间','',201);  
468 - //获取uuid对应的手机号  
469 - $where = ['and', "uuid = '{$uuid}'"];  
470 - $account = $this->OrderDao->getAccountInfo($where);  
471 - $mobile = $account['mobile'];  
472 - //生成入库数组  
473 - $order_data['order_id'] = $this->genOrderID();  
474 - $order_data['supplier_no'] = $input['supplier_no'];  
475 - $order_data['service_type'] = $input['service_type'];  
476 - $order_data['sex'] = $input['sex'];  
477 - $order_data['select_data'] = $input['select_data'];  
478 - $order_data['data_note'] = $input['data_note'];  
479 - $order_data['start_time'] = $input['start_time'];  
480 - $order_data['order_note'] = $input['order_note'];  
481 - $order_data['order_status'] = 10;  
482 - $order_data['mobile'] = $mobile;  
483 -  
484 - //坐席释放时间  
485 - $release_time = strtotime($input['staff_release_time']) - time();  
486 - // if($release_time < 86400 || $release_time > 2592000) Helper::show('席位释放时间需在1至30天内','',201);  
487 - $order_data['staff_release_time'] = strtotime($input['staff_release_time']);  
488 -  
489 - //订单聊天结束时间  
490 - $chat_time = strtotime($input['chat_end_fan_time']) - time();  
491 - $order_data['chat_end_fan_time'] = strtotime($input['chat_end_fan_time']);  
492 -  
493 - //判断是云控台还是云订单  
494 - if($input['system_type'] == 2){  
495 - //下单状态order_status=20接单用户UUID cloud_console_uuid = 自己  
496 - $order_data['order_status'] = 20;  
497 - $order_data['order_cloud_console_status'] = 20;  
498 - $order_data['cloud_console_uuid'] = $uuid;  
499 - }  
500 -  
501 - $distribution_ids = [];  
502 - //判断服务类型,0畅聊1导粉  
503 - if($input['service_type'] == 2){// 转化底粉  
504 - //验证相关字段是否为空  
505 -  
506 - $staff_distribution = json_decode($input['staff_distribution'],true);  
507 - if(empty($staff_distribution)) Helper::show('坐席分配未设置','',201);  
508 - //检测坐席格式  
509 - $arr = json_decode($input['staff_distribution'],true);  
510 - foreach ($arr as $item) {  
511 - if(!isset($item['id']) || !isset($item['alias']) || !isset($item['username'])) Helper::show('坐席分配格式错误','',201);  
512 - $distribution_ids[] = $item['id'];  
513 - }  
514 - $url = Yii::$app->params['chat_url'];  
515 - //发送数据包到对应接口  
516 -  
517 - //发送post-》grouping  
518 - $data = ['uuid' => $uuid,'group_name' => '未分组','order_uunum' => $order_data['order_id'],'first' => 1];  
519 - $post = $this->sendPost($url.'grouping',$data);  
520 - Helper::writeLog('Order','订单分组:'.$post);  
521 - //循环发送group_name-》grouping  
522 - if(isset($input['is_group']) && $input['is_group'] == 1){  
523 - $arr = json_decode($input['group_name'],true);  
524 - foreach ($arr as $key => $value) {  
525 - $data = ['uuid' => $uuid,'group_name' => $value,'order_uunum' => $order_data['order_id'],'first' => 0];  
526 - $post = $this->sendPost($url.'grouping',$data);  
527 - Helper::writeLog('Order','订单分组循环:'.$post);  
528 - }  
529 - }  
530 -  
531 - //判断订单系统 开启素材库 1开启 0关闭(默认)  
532 - if(isset($input['is_material']) && $input['is_material'] == 1){  
533 - $arr = json_decode($input['material_group'],true);  
534 - foreach ($arr as $key => $value) {  
535 - //循环发送material_group-》addOrderMaterial  
536 - $data = ['uuid' => $uuid,'status' => $value['status'],'order_order_id' => $order_data['order_id'],'group_id' => $value['group_id']];  
537 - $data = json_encode($data);  
538 - $post = $this->sendPost($url.'addOrderMaterial',$data);  
539 - Helper::writeLog('Order','开启素材库:'.$post);  
540 - }  
541 - }  
542 -  
543 - //判断畅聊系统 开启快捷回复 1开启 0关闭(默认)  
544 - if(isset($input['is_quick_reply']) && $input['is_quick_reply'] == 1){  
545 - //发送数据-》addOrderQuickReply  
546 - $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'group_id' => $input['quick_reply_group']];  
547 - $data = json_encode($data);  
548 - $post = $this->sendPost($url.'addOrderQuickReply',$data);  
549 - Helper::writeLog('Order','快捷回复:'.$post);  
550 - }  
551 -  
552 - //判断订单系统 开启关键词回复 1开启 0关闭(默认)  
553 - if(isset($input['is_keyword']) && $input['is_keyword'] == 1){  
554 - //发送数据-》addOrderKeyword  
555 - $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'group_id' => $input['keyword_group']];  
556 - $data = json_encode($data);  
557 - $post = $this->sendPost($url.'addOrderKeyword',$data);  
558 - Helper::writeLog('Order','关键词回复:'.$post);  
559 - $order_data['keyword_begin_time'] = isset($input['keyword_begin_time'])?$input['keyword_begin_time']:'00:00';  
560 - $order_data['keyword_end_time'] = isset($input['keyword_end_time'])?$input['keyword_end_time']:'24:00';  
561 - }  
562 -  
563 - //判断订单系统 开启自动回复 1开启 0关闭(默认)  
564 - if(isset($input['is_auto_reply']) && $input['is_auto_reply']){  
565 - //发送数据包-》addOrderAutoreply  
566 - $data = ['uuid' => $uuid,'id' => $input['auto_reply_id'],'order_order_id' => $order_data['order_id']];  
567 - $data = json_encode($data);  
568 - $post = $this->sendPost($url.'addOrderAutoreply',$data);  
569 - Helper::writeLog('Order','自动回复:'.$post);  
570 - $order_data['autoreply_begin_time'] = isset($input['autoreply_begin_time'])?$input['autoreply_begin_time']:'00:00';  
571 - $order_data['autoreply_end_time'] = isset($input['autoreply_end_time'])?$input['autoreply_end_time']:'24:00';  
572 - }  
573 -  
574 - //判断选择验证语ID  
575 - if(isset($input['verifying_language_id'])){  
576 - $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'id' => $input['verifying_language_id']];  
577 - $data = json_encode($data);  
578 - $post = $this->sendPost($url.'addOrderVerifyingLanguage',$data);  
579 - Helper::writeLog('Order','验证语:'.$post);  
580 - }  
581 -  
582 - //判断是否拉群  
583 - if(isset($input['is_colony']) && $input['is_colony'] == 1){  
584 - $colony_data = json_decode($input['colony_data'],true);  
585 - if(empty($colony_data)) Helper::show('拉群配置不能为空','',201);  
586 - //组装数据包  
587 - $data = [];  
588 - $data['uuid'] = $uuid;  
589 - $data['order_id'] = $order_data['order_id'];  
590 - $data['open_add_chat_room'] = true;  
591 - $data['chat_room_mode'] = $colony_data['chat_room_mode'];  
592 - $data['small_into_chat_room_limit_num'] =  
593 - $colony_data['small_into_chat_room_limit_num'];  
594 - $data['small_invite_fans_wait_limit_num'] =  
595 - $colony_data['small_invite_fans_wait_limit_num'];  
596 - $data['start_invite_fans_into_chat_room_num'] =  
597 - $colony_data['start_invite_fans_into_chat_room_num'];  
598 - $data['quit_chat_room_time'] = $colony_data['quit_chat_room_time'];  
599 - $data['into_chat_room_interval'] = $colony_data['into_chat_room_interval'];  
600 - $data['end_invite_fans_into_chat_room_time'] = $colony_data['end_invite_fans_into_chat_room_time'];  
601 - $data['code_ids'] = $colony_data['code_ids'];  
602 - Helper::writeLog('Order','拉群请求参数:'.json_encode($data));  
603 - //请求存储拉群配置接口  
604 - $url = Yii::$app->params['cloud_url'] . 'chat_room/config/save_chat_room_config';  
605 - $post = $this->sendPost($url, json_encode($data) , Yii::$app->params['origin_cloud_add_fans']);  
606 - Helper::writeLog('Order','拉群:'.$post);  
607 - }  
608 -  
609 - //添加开关字段  
610 - $order_data['is_hide_moblie'] = $input['is_hide_moblie'];  
611 - $order_data['is_quick_reply'] = $input['is_quick_reply'];  
612 - $order_data['is_get_fan_nickname'] = $input['is_get_fan_nickname'];  
613 - $order_data['is_material'] = $input['is_material'];  
614 - $order_data['is_keyword'] = $input['is_keyword'];  
615 - $order_data['is_auto_reply'] = $input['is_auto_reply'];  
616 - $order_data['is_group'] = $input['is_group'];  
617 - $order_data['staff_distribution'] = $input['staff_distribution'];  
618 - $order_data['is_del_repeat'] = isset($input['is_del_repeat'])?$input['is_del_repeat']:0;  
619 -  
620 - }  
621 -  
622 - $order_data['uuid'] = $uuid;  
623 -  
624 - // 食物链最上游的订单号  
625 - $order_data['top_order_id'] = $order_data['order_id'];  
626 - // 密钥  
627 - $order_data['order_secret'] = $this->genOrderSecret();  
628 -  
629 - $this->OrderDao->addOrderData($order_data);  
630 -  
631 - $order_id = $order_data['order_id'];  
632 -  
633 - // 下单成功后的数据回写  
634 - $updata = ['is_distribution' => 1, 'is_distribution_chat' => 1, 'order_order_id' => $order_id,'is_hide_moblie' => $input['is_hide_moblie'], 'is_auto_reply' => $input['is_auto_reply'], 'is_auto_reply_chat' => $input['is_auto_reply'], 'is_keyword' => $input['is_keyword'], 'is_keyword_chat' => $input['is_keyword'], 'is_release' => 0];  
635 - $distribution_ids = implode(',',$distribution_ids);  
636 - if(!empty($distribution_ids)){  
637 - $where = "uuid = '{$uuid}' AND id IN ($distribution_ids)";  
638 - //更新nt_staff  
639 - $this->OrderDao->editStaffData($where,$updata);  
640 - }  
641 -  
642 - //坐席释放时间,单位/天,0等于不限时  
643 - if($release_time > 0){  
644 - //投递延时任务  
645 - $task = [  
646 - 'type' => 1,  
647 - 'order_id' => $order_data['order_id'],  
648 - 'time' => strtotime(date('Y-m-d') . ' 09:30:00') + 86400,  
649 - ];  
650 - Yii::$app->order->delay($release_time)->push(new \app\jobs\Order($task));  
651 - }  
652 -  
653 - //聊天结束时间,大于十年则是无限,不投递任务  
654 - $month_time = 86400 * 365 * 10;  
655 - $month_date = $chat_time - time();  
656 - if($chat_time > 0 && $month_date < $month_time){  
657 - //投递延时任务  
658 - $task = [  
659 - 'type' => 2,  
660 - 'order_id' => $order_data['order_id'],  
661 - 'time' => strtotime($input['chat_end_fan_time']),  
662 - ];  
663 - Yii::$app->order->delay($chat_time)->push(new \app\jobs\Order($task));  
664 - }  
665 -  
666 - $res['order_id'] = $order_data['order_id'];  
667 - $res['order_secret'] = $order_data['order_secret'];  
668 -  
669 - return $res;  
670 - }  
671 -  
672 - public function addFacebookOrder($input){  
673 - // $this->facebookValidator($input);//参数过滤器  
674 - $uuid = $input['uuid'];  
675 - //获取uuid对应的手机号  
676 - $where = ['and', "uuid = '{$uuid}'"];  
677 - $account = $this->OrderDao->getAccountInfo($where);  
678 - $mobile = $account['mobile'];  
679 -  
680 - //生成入库数组  
681 - $order_data['order_id'] = $this->genOrderID();  
682 - $order_data['service_type'] = $input['service_type'];  
683 - $order_data['sex'] = $input['sex'];  
684 - $order_data['select_data'] = $input['select_data'];  
685 - $order_data['data_note'] = $input['data_note'];  
686 - $order_data['start_time'] = $input['start_time'];  
687 - $order_data['order_note'] = $input['order_note'];  
688 - $order_data['order_status'] = 10;  
689 - $order_data['mobile'] = $mobile;  
690 - $order_data['target_countries'] = $input['target_countries'];  
691 -  
692 - //坐席释放时间  
693 - $release_time = strtotime($input['staff_release_time']) - time();  
694 - // if($release_time < 86400 || $release_time > 2592000) Helper::show('席位释放时间需在1至30天内','',201);  
695 - $order_data['staff_release_time'] = strtotime($input['staff_release_time']);  
696 -  
697 - //订单聊天结束时间  
698 - $chat_time = strtotime($input['chat_end_fan_time']) - time();  
699 - $order_data['chat_end_fan_time'] = strtotime($input['chat_end_fan_time']);  
700 -  
701 - //判断是云控台还是云订单  
702 - if($input['system_type'] == 2){  
703 - //下单状态order_status=20接单用户UUID cloud_console_uuid = 自己  
704 - $order_data['order_status'] = 20;  
705 - $order_data['order_cloud_console_status'] = 20;  
706 - $order_data['cloud_console_uuid'] = $uuid;  
707 - }  
708 - //判断数据选择,0随机1精准数据  
709 - if($input['select_data'] == 1){  
710 - if(empty($input['data_warehouse_id']) || empty($input['data_warehouse_detail'])) Helper::show('缺少data_warehouse_id或data_warehouse_detail','',201);  
711 - //获取目录名  
712 - $where = ['and',"uuid = '{$uuid}'","id = {$input['data_warehouse_id']}"];  
713 - $warehouse = $this->OrderDao->getWarehouseInfo($where);  
714 - $order_data['data_warehouse_id'] = $input['data_warehouse_id'];  
715 - $order_data['data_warehouse_detail'] = $input['data_warehouse_detail'];  
716 - $order_data['data_warehouse_folder_name'] = $warehouse['folder_name'];  
717 - }  
718 - $distribution_ids = [];  
719 - //判断服务类型,0畅聊1导粉2转化底粉3脸书  
720 - if($input['service_type'] == 3){//脸书  
721 - //验证相关字段是否为空  
722 - $order_data['target_total'] = $input['target_total'];  
723 -  
724 - $staff_distribution = json_decode($input['staff_distribution'],true);  
725 - if(empty($staff_distribution)) Helper::show('坐席分配未设置','',201);  
726 - //检测坐席格式  
727 - $arr = json_decode($input['staff_distribution'],true);  
728 - foreach ($arr as $item) {  
729 - if(!isset($item['id']) || !isset($item['alias']) || !isset($item['username'])) Helper::show('坐席分配格式错误','',201);  
730 - $distribution_ids[] = $item['id'];  
731 - }  
732 - $url = Yii::$app->params['chat_url'];  
733 - //发送数据包到对应接口  
734 -  
735 - //发送post-》grouping  
736 - $data = ['uuid' => $uuid,'group_name' => '未分组','order_uunum' => $order_data['order_id'],'first' => 1];  
737 - $post = $this->sendPost($url.'grouping',$data);  
738 - Helper::writeLog('Order','订单分组:'.$post);  
739 - //循环发送group_name-》grouping  
740 - if(isset($input['is_group']) && $input['is_group'] == 1){  
741 - $arr = json_decode($input['group_name'],true);  
742 - foreach ($arr as $key => $value) {  
743 - $data = ['uuid' => $uuid,'group_name' => $value,'order_uunum' => $order_data['order_id'],'first' => 0];  
744 - $post = $this->sendPost($url.'grouping',$data);  
745 - Helper::writeLog('Order','订单分组循环:'.$post);  
746 - }  
747 - }  
748 -  
749 - //判断订单系统 开启素材库 1开启 0关闭(默认)  
750 - if(isset($input['is_material']) && $input['is_material'] == 1){  
751 - $arr = json_decode($input['material_group'],true);  
752 - foreach ($arr as $key => $value) {  
753 - //循环发送material_group-》addOrderMaterial  
754 - $data = ['uuid' => $uuid,'status' => $value['status'],'order_order_id' => $order_data['order_id'],'group_id' => $value['group_id']];  
755 - $data = json_encode($data);  
756 - $post = $this->sendPost($url.'addOrderMaterial',$data);  
757 - Helper::writeLog('Order','开启素材库:'.$post);  
758 - }  
759 - }  
760 -  
761 - //判断畅聊系统 开启快捷回复 1开启 0关闭(默认)  
762 - if(isset($input['is_quick_reply']) && $input['is_quick_reply'] == 1){  
763 - //发送数据-》addOrderQuickReply  
764 - $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'group_id' => $input['quick_reply_group']];  
765 - $data = json_encode($data);  
766 - $post = $this->sendPost($url.'addOrderQuickReply',$data);  
767 - Helper::writeLog('Order','快捷回复:'.$post);  
768 - }  
769 -  
770 - //判断订单系统 开启关键词回复 1开启 0关闭(默认)  
771 - if(isset($input['is_keyword']) && $input['is_keyword'] == 1){  
772 - //发送数据-》addOrderKeyword  
773 - $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'group_id' => $input['keyword_group']];  
774 - $data = json_encode($data);  
775 - $post = $this->sendPost($url.'addOrderKeyword',$data);  
776 - Helper::writeLog('Order','关键词回复:'.$post);  
777 - $order_data['keyword_begin_time'] = isset($input['keyword_begin_time'])?$input['keyword_begin_time']:'00:00';  
778 - $order_data['keyword_end_time'] = isset($input['keyword_end_time'])?$input['keyword_end_time']:'24:00';  
779 - }  
780 -  
781 - //判断订单系统 开启自动回复 1开启 0关闭(默认)  
782 - if(isset($input['is_auto_reply']) && $input['is_auto_reply']){  
783 - //发送数据包-》addOrderAutoreply  
784 - $data = ['uuid' => $uuid,'id' => $input['auto_reply_id'],'order_order_id' => $order_data['order_id']];  
785 - $data = json_encode($data);  
786 - $post = $this->sendPost($url.'addOrderAutoreply',$data);  
787 - Helper::writeLog('Order','自动回复:'.$post);  
788 - $order_data['autoreply_begin_time'] = isset($input['autoreply_begin_time'])?$input['autoreply_begin_time']:'00:00';  
789 - $order_data['autoreply_end_time'] = isset($input['autoreply_end_time'])?$input['autoreply_end_time']:'24:00';  
790 - }  
791 -  
792 - //判断选择验证语ID  
793 - if(isset($input['verifying_language_id'])){  
794 - $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'id' => $input['verifying_language_id']];  
795 - $data = json_encode($data);  
796 - $post = $this->sendPost($url.'addOrderVerifyingLanguage',$data);  
797 - Helper::writeLog('Order','验证语:'.$post);  
798 - }  
799 -  
800 - //添加开关字段  
801 - $order_data['is_hide_moblie'] = $input['is_hide_moblie'];  
802 - $order_data['is_quick_reply'] = $input['is_quick_reply'];  
803 - $order_data['is_get_fan_nickname'] = $input['is_get_fan_nickname'];  
804 - $order_data['is_material'] = $input['is_material'];  
805 - $order_data['is_keyword'] = $input['is_keyword'];  
806 - $order_data['is_auto_reply'] = $input['is_auto_reply'];  
807 - $order_data['is_group'] = $input['is_group'];  
808 - $order_data['staff_distribution'] = $input['staff_distribution'];  
809 -  
810 - }  
811 -  
812 - // Helper::writeLog('Order','订单的is_hide_moblie:'.$input['is_hide_moblie']);  
813 -  
814 - $order_data['uuid'] = $uuid;  
815 -  
816 - // 食物链最上游的订单号  
817 - $order_data['top_order_id'] = $order_data['order_id'];  
818 - // 密钥  
819 - $order_data['order_secret'] = $this->genOrderSecret();  
820 -  
821 - $this->OrderDao->addOrderData($order_data);  
822 -  
823 - $order_id = $order_data['order_id'];  
824 -  
825 - // 下单成功后的数据回写  
826 - $updata = ['is_distribution' => 1, 'is_distribution_chat' => 1, 'order_order_id' => $order_id,'is_hide_moblie' => $input['is_hide_moblie'], 'is_auto_reply' => $input['is_auto_reply'], 'is_auto_reply_chat' => $input['is_auto_reply'], 'is_keyword' => $input['is_keyword'], 'is_keyword_chat' => $input['is_keyword'], 'is_release' => 0];  
827 - Helper::writeLog('Order','订单的 updata:'.json_encode($updata));  
828 - $distribution_ids = implode(',',$distribution_ids);  
829 - Helper::writeLog('Order','订单的 distribution_ids:'.json_encode($distribution_ids));  
830 - if(!empty($distribution_ids)){  
831 - $where = "uuid = '{$uuid}' AND id IN ($distribution_ids)";  
832 - Helper::writeLog('Order','订单的 where:'.$where);  
833 - //更新nt_staff  
834 - $this->OrderDao->editStaffData($where,$updata);  
835 - }  
836 -  
837 - //坐席释放时间,单位/天,0等于不限时  
838 - if($release_time > 0){  
839 - //投递延时任务  
840 - $task = [  
841 - 'type' => 1,  
842 - 'order_id' => $order_data['order_id'],  
843 - 'time' => strtotime(date('Y-m-d') . ' 09:30:00') + 86400,  
844 - ];  
845 - Yii::$app->order->delay($release_time)->push(new \app\jobs\Order($task));  
846 - }  
847 -  
848 - //聊天结束时间,大于十年则是无限,不投递任务  
849 - $month_time = 86400 * 365 * 10;  
850 - $month_date = $chat_time - time();  
851 - if($chat_time > 0 && $month_date < $month_time){  
852 - //投递延时任务  
853 - $task = [  
854 - 'type' => 2,  
855 - 'order_id' => $order_data['order_id'],  
856 - 'time' => strtotime($input['chat_end_fan_time']),  
857 - ];  
858 - Yii::$app->order->delay($chat_time)->push(new \app\jobs\Order($task)); 141 + /**
  142 + * 处理添加订单逻辑
  143 + * @param $input
  144 + */
  145 + public function handleAddOrder($input) {
  146 + if (!isset($input['service_type']) || !is_numeric($input['service_type'])) {
  147 + return false;
  148 + }
  149 +
  150 + // 判断服务类型
  151 + switch ((int)$input['service_type']) {
  152 + case 0: // 畅聊
  153 + $data = (new ChatOrderStrategy($this->OrderDao))->handle($input);
  154 + break;
  155 + case 2: // 转化底粉
  156 + $data = (new BottomFansStrategy($this->OrderDao))->handle($input);
  157 + break;
  158 + case 3: // facebook
  159 + $data = (new FacebookOrderStrategy($this->OrderDao))->handle($input);
  160 + break;
  161 + case 4: // what's app
  162 + $data = (new WhatAppOrderStrategy($this->OrderDao))->handle($input);
  163 + break;
  164 + default:
  165 + return false;
859 } 166 }
860 167
861 - // push队列初始化分组  
862 - Yii::$app->order->push(new \app\jobs\Order([  
863 - 'type' => 3,  
864 - 'order_id' => $order_data['order_id']  
865 - ]));  
866 -  
867 - $res['order_id'] = $order_data['order_id'];  
868 - $res['order_secret'] = $order_data['order_secret'];  
869 -  
870 - return $res; 168 + return $data;
871 } 169 }
872 170
  171 + /**
  172 + * 关闭订单
  173 + * @param $input
  174 + */
873 public function closeOrderData($input){ 175 public function closeOrderData($input){
874 $order_id = $input['order_id']; 176 $order_id = $input['order_id'];
875 $where = ['and',"uuid = '{$input['uuid']}'","order_id = '{$order_id}'"]; 177 $where = ['and',"uuid = '{$input['uuid']}'","order_id = '{$order_id}'"];
@@ -892,6 +194,10 @@ class OrderLogic @@ -892,6 +194,10 @@ class OrderLogic
892 return; 194 return;
893 } 195 }
894 196
  197 + /**
  198 + * 删除订单
  199 + * @param $input
  200 + */
895 public function delOrderData($input){ 201 public function delOrderData($input){
896 $order_id = $input['order_id']; 202 $order_id = $input['order_id'];
897 $where = ['and',"uuid = '{$input['uuid']}'","order_id = '{$order_id}'"]; 203 $where = ['and',"uuid = '{$input['uuid']}'","order_id = '{$order_id}'"];
@@ -907,7 +213,12 @@ class OrderLogic @@ -907,7 +213,12 @@ class OrderLogic
907 return; 213 return;
908 } 214 }
909 215
910 - public function backDistribution($order_id,$staff_distribution){ 216 + /**
  217 + * 恢复畅聊坐席
  218 + * @param $order_id
  219 + * @param $staff_distribution
  220 + */
  221 + protected function backDistribution($order_id,$staff_distribution){
911 $staff_distribution = json_decode($staff_distribution,true); 222 $staff_distribution = json_decode($staff_distribution,true);
912 if(is_string($staff_distribution)) $staff_distribution = json_decode($staff_distribution,true); 223 if(is_string($staff_distribution)) $staff_distribution = json_decode($staff_distribution,true);
913 if(!empty($staff_distribution) && is_array($staff_distribution)){ 224 if(!empty($staff_distribution) && is_array($staff_distribution)){
@@ -920,86 +231,4 @@ class OrderLogic @@ -920,86 +231,4 @@ class OrderLogic
920 $this->OrderDao->editStaffData($where,$data); 231 $this->OrderDao->editStaffData($where,$data);
921 } 232 }
922 } 233 }
923 -  
924 - /**  
925 - * 生成密钥  
926 - */  
927 - protected function genOrderSecret() {  
928 - $secret = $this->createRandStr(10, '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ');  
929 - //获取订单秘钥,判断是否存在  
930 - $where = ['and',"order_secret = '{$secret}'"];  
931 - $order_info = $this->OrderDao->getOrderInfo($where);  
932 - if (empty($order_info)) {  
933 - return $secret;  
934 - } else {  
935 - // HACK  
936 - return $this->genOrderSecret();  
937 - }  
938 - }  
939 -  
940 - /**  
941 - * 随机字符串生成  
942 - * @param int $len 需要随机的长度,不要太长  
943 - * @param string $chars 随机生成字符串的范围  
944 - *  
945 - * @return string  
946 - */  
947 - public function createRandStr($len, $chars = null) {  
948 - if (!$chars) {  
949 - $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';  
950 - }  
951 -  
952 - return substr(str_shuffle(str_repeat($chars, rand(5, 8))), 0, $len);  
953 - }  
954 -  
955 - function sendPost($url, $data , $origin = '') { // 模拟提交数据函数  
956 - $curl = curl_init(); // 启动一个CURL会话  
957 - curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址  
958 - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查  
959 - curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在  
960 -// curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器  
961 - if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {  
962 - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转  
963 - } curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer  
964 - if(!empty($origin)){  
965 - $header=array(  
966 - "Accept: application/json",  
967 - "Content-Type: application/json;charset=utf-8",  
968 - "Origin: " . $origin,  
969 - );  
970 - curl_setopt($curl,CURLOPT_HTTPHEADER,$header);  
971 - }  
972 - curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求  
973 - curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包  
974 - curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环  
975 - curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容  
976 - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回  
977 - $tmpInfo = curl_exec($curl); // 执行操作  
978 - if (curl_errno($curl)) {  
979 - echo 'Errno' . curl_error($curl);  
980 - }  
981 - curl_close($curl); // 关键CURL会话  
982 -  
983 - return $tmpInfo; // 返回数据  
984 - }  
985 -  
986 - /**  
987 - * 生成订单号  
988 - */  
989 - protected function genOrderID() {  
990 - //查询订单表大于今天的统计总数  
991 - $today = date('Y-m-d') . ' 00:00:00';  
992 - $where = ['and', "add_time >= '{$today}'"];  
993 - $count = $this->OrderDao->getOrderCount($where);  
994 - $total = isset($count) ? $count : 0;  
995 - $code = sprintf('%s%s%s%s', substr(date('Y'), 2), date('dm'), $total + 1 + 126, date('s')); // 126是起始值  
996 - //查库是否存在  
997 - $where = ['and', "order_id = '{$code}'"];  
998 - $info = $this->OrderDao->getOrderInfo($where);  
999 - if(empty($info)){  
1000 - return $code;  
1001 - }else{  
1002 - return $this->genOrderID();  
1003 - }  
1004 - }  
1005 -}  
  234 +}
  1 +<?php
  2 +/**
  3 + * @class WhatAppOrderStrategy
  4 + * @package app\logic
  5 + * @date 2021/05/20 14:26
  6 + */
  7 +
  8 +namespace app\logic;
  9 +
  10 +use \Yii;
  11 +use app\common\Helper;
  12 +
  13 +class WhatAppOrderStrategy extends BaseOrderStrategy
  14 +{
  15 +
  16 + public function handle($input)
  17 + {
  18 + $uuid = $input['uuid'];
  19 + //获取uuid对应的手机号
  20 + $where = ['and', "uuid = '{$uuid}'"];
  21 + $account = $this->orderDao->getAccountInfo($where);
  22 + $mobile = $account['mobile'];
  23 +
  24 + //生成入库数组
  25 + $order_data['order_id'] = $this->genOrderID();
  26 + $order_data['service_type'] = $input['service_type'];
  27 + $order_data['sex'] = $input['sex'];
  28 + $order_data['select_data'] = $input['select_data'];
  29 + $order_data['data_note'] = $input['data_note'];
  30 + $order_data['start_time'] = $input['start_time'];
  31 + $order_data['order_note'] = $input['order_note'];
  32 + $order_data['order_status'] = 10;
  33 + $order_data['mobile'] = $mobile;
  34 + $order_data['target_countries'] = $input['target_countries'];
  35 +
  36 + //坐席释放时间
  37 + $release_time = strtotime($input['staff_release_time']) - time();
  38 + // if($release_time < 86400 || $release_time > 2592000) Helper::show('席位释放时间需在1至30天内','',201);
  39 + $order_data['staff_release_time'] = strtotime($input['staff_release_time']);
  40 +
  41 + //订单聊天结束时间
  42 + $chat_time = strtotime($input['chat_end_fan_time']) - time();
  43 + $order_data['chat_end_fan_time'] = strtotime($input['chat_end_fan_time']);
  44 +
  45 + //判断是云控台还是云订单
  46 + if($input['system_type'] == 2){
  47 + //下单状态order_status=20接单用户UUID cloud_console_uuid = 自己
  48 + $order_data['order_status'] = 20;
  49 + $order_data['order_cloud_console_status'] = 20;
  50 + $order_data['cloud_console_uuid'] = $uuid;
  51 + }
  52 + //判断数据选择,0随机1精准数据
  53 + if($input['select_data'] == 1){
  54 + if(empty($input['data_warehouse_id']) || empty($input['data_warehouse_detail'])) Helper::show('缺少data_warehouse_id或data_warehouse_detail','',201);
  55 + //获取目录名
  56 + $where = ['and',"uuid = '{$uuid}'","id = {$input['data_warehouse_id']}"];
  57 + $warehouse = $this->orderDao->getWarehouseInfo($where);
  58 + $order_data['data_warehouse_id'] = $input['data_warehouse_id'];
  59 + $order_data['data_warehouse_detail'] = $input['data_warehouse_detail'];
  60 + $order_data['data_warehouse_folder_name'] = $warehouse['folder_name'];
  61 + }
  62 + $distribution_ids = [];
  63 + //判断服务类型,0畅聊1导粉2转化底粉3脸书
  64 + //验证相关字段是否为空
  65 + $order_data['target_total'] = $input['target_total'];
  66 +
  67 + $staff_distribution = json_decode($input['staff_distribution'],true);
  68 + if(empty($staff_distribution)) Helper::show('坐席分配未设置','',201);
  69 + //检测坐席格式
  70 + $arr = json_decode($input['staff_distribution'],true);
  71 + foreach ($arr as $item) {
  72 + if(!isset($item['id']) || !isset($item['alias']) || !isset($item['username'])) Helper::show('坐席分配格式错误','',201);
  73 + $distribution_ids[] = $item['id'];
  74 + }
  75 + $url = Yii::$app->params['chat_url'];
  76 + //发送数据包到对应接口
  77 +
  78 + //发送post-》grouping
  79 + $data = ['uuid' => $uuid,'group_name' => '未分组','order_uunum' => $order_data['order_id'],'first' => 1];
  80 + $post = $this->sendPost($url.'grouping',$data);
  81 + Helper::writeLog('Order','订单分组:'.$post);
  82 + //循环发送group_name-》grouping
  83 + if(isset($input['is_group']) && $input['is_group'] == 1){
  84 + $arr = json_decode($input['group_name'],true);
  85 + foreach ($arr as $key => $value) {
  86 + $data = ['uuid' => $uuid,'group_name' => $value,'order_uunum' => $order_data['order_id'],'first' => 0];
  87 + $post = $this->sendPost($url.'grouping',$data);
  88 + Helper::writeLog('Order','订单分组循环:'.$post);
  89 + }
  90 + }
  91 +
  92 + //判断订单系统 开启素材库 1开启 0关闭(默认)
  93 + if(isset($input['is_material']) && $input['is_material'] == 1){
  94 + $arr = json_decode($input['material_group'],true);
  95 + foreach ($arr as $key => $value) {
  96 + //循环发送material_group-》addOrderMaterial
  97 + $data = ['uuid' => $uuid,'status' => $value['status'],'order_order_id' => $order_data['order_id'],'group_id' => $value['group_id']];
  98 + $data = json_encode($data);
  99 + $post = $this->sendPost($url.'addOrderMaterial',$data);
  100 + Helper::writeLog('Order','开启素材库:'.$post);
  101 + }
  102 + }
  103 +
  104 + //判断畅聊系统 开启快捷回复 1开启 0关闭(默认)
  105 + if(isset($input['is_quick_reply']) && $input['is_quick_reply'] == 1){
  106 + //发送数据-》addOrderQuickReply
  107 + $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'group_id' => $input['quick_reply_group']];
  108 + $data = json_encode($data);
  109 + $post = $this->sendPost($url.'addOrderQuickReply',$data);
  110 + Helper::writeLog('Order','快捷回复:'.$post);
  111 + }
  112 +
  113 + //判断订单系统 开启关键词回复 1开启 0关闭(默认)
  114 + if(isset($input['is_keyword']) && $input['is_keyword'] == 1){
  115 + //发送数据-》addOrderKeyword
  116 + $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'group_id' => $input['keyword_group']];
  117 + $data = json_encode($data);
  118 + $post = $this->sendPost($url.'addOrderKeyword',$data);
  119 + Helper::writeLog('Order','关键词回复:'.$post);
  120 + $order_data['keyword_begin_time'] = isset($input['keyword_begin_time'])?$input['keyword_begin_time']:'00:00';
  121 + $order_data['keyword_end_time'] = isset($input['keyword_end_time'])?$input['keyword_end_time']:'24:00';
  122 + }
  123 +
  124 + //判断订单系统 开启自动回复 1开启 0关闭(默认)
  125 + if(isset($input['is_auto_reply']) && $input['is_auto_reply']){
  126 + //发送数据包-》addOrderAutoreply
  127 + $data = ['uuid' => $uuid,'id' => $input['auto_reply_id'],'order_order_id' => $order_data['order_id']];
  128 + $data = json_encode($data);
  129 + $post = $this->sendPost($url.'addOrderAutoreply',$data);
  130 + Helper::writeLog('Order','自动回复:'.$post);
  131 + $order_data['autoreply_begin_time'] = isset($input['autoreply_begin_time'])?$input['autoreply_begin_time']:'00:00';
  132 + $order_data['autoreply_end_time'] = isset($input['autoreply_end_time'])?$input['autoreply_end_time']:'24:00';
  133 + }
  134 +
  135 + //判断选择验证语ID
  136 + if(isset($input['verifying_language_id'])){
  137 + $data = ['uuid' => $uuid,'order_order_id' => $order_data['order_id'],'id' => $input['verifying_language_id']];
  138 + $data = json_encode($data);
  139 + $post = $this->sendPost($url.'addOrderVerifyingLanguage',$data);
  140 + Helper::writeLog('Order','验证语:'.$post);
  141 + }
  142 +
  143 + //添加开关字段
  144 + $order_data['is_hide_moblie'] = $input['is_hide_moblie'];
  145 + $order_data['is_quick_reply'] = $input['is_quick_reply'];
  146 + $order_data['is_get_fan_nickname'] = $input['is_get_fan_nickname'];
  147 + $order_data['is_material'] = $input['is_material'];
  148 + $order_data['is_keyword'] = $input['is_keyword'];
  149 + $order_data['is_auto_reply'] = $input['is_auto_reply'];
  150 + $order_data['is_group'] = $input['is_group'];
  151 + $order_data['staff_distribution'] = $input['staff_distribution'];
  152 +
  153 + // Helper::writeLog('Order','订单的is_hide_moblie:'.$input['is_hide_moblie']);
  154 +
  155 + $order_data['uuid'] = $uuid;
  156 +
  157 + // 食物链最上游的订单号
  158 + $order_data['top_order_id'] = $order_data['order_id'];
  159 + // 密钥
  160 + $order_data['order_secret'] = $this->genOrderSecret();
  161 +
  162 + $this->orderDao->addOrderData($order_data);
  163 +
  164 + $order_id = $order_data['order_id'];
  165 +
  166 + // 下单成功后的数据回写
  167 + $updata = ['is_distribution' => 1, 'is_distribution_chat' => 1, 'order_order_id' => $order_id,'is_hide_moblie' => $input['is_hide_moblie'], 'is_auto_reply' => $input['is_auto_reply'], 'is_auto_reply_chat' => $input['is_auto_reply'], 'is_keyword' => $input['is_keyword'], 'is_keyword_chat' => $input['is_keyword'], 'is_release' => 0];
  168 + Helper::writeLog('Order','订单的 updata:'.json_encode($updata));
  169 + $distribution_ids = implode(',',$distribution_ids);
  170 + Helper::writeLog('Order','订单的 distribution_ids:'.json_encode($distribution_ids));
  171 + if(!empty($distribution_ids)){
  172 + $where = "uuid = '{$uuid}' AND id IN ($distribution_ids)";
  173 + Helper::writeLog('Order','订单的 where:'.$where);
  174 + //更新nt_staff
  175 + $this->orderDao->editStaffData($where,$updata);
  176 + }
  177 +
  178 + //坐席释放时间,单位/天,0等于不限时
  179 + if($release_time > 0){
  180 + //投递延时任务
  181 + $task = [
  182 + 'type' => 1,
  183 + 'order_id' => $order_data['order_id'],
  184 + 'time' => strtotime(date('Y-m-d') . ' 09:30:00') + 86400,
  185 + ];
  186 + Yii::$app->order->delay($release_time)->push(new \app\jobs\Order($task));
  187 + }
  188 +
  189 + //聊天结束时间,大于十年则是无限,不投递任务
  190 + $month_time = 86400 * 365 * 10;
  191 + $month_date = $chat_time - time();
  192 + if($chat_time > 0 && $month_date < $month_time){
  193 + //投递延时任务
  194 + $task = [
  195 + 'type' => 2,
  196 + 'order_id' => $order_data['order_id'],
  197 + 'time' => strtotime($input['chat_end_fan_time']),
  198 + ];
  199 + Yii::$app->order->delay($chat_time)->push(new \app\jobs\Order($task));
  200 + }
  201 +
  202 + // push队列初始化分组
  203 + Yii::$app->order->push(new \app\jobs\Order([
  204 + 'type' => 3,
  205 + 'order_id' => $order_data['order_id']
  206 + ]));
  207 +
  208 + $res['order_id'] = $order_data['order_id'];
  209 + $res['order_secret'] = $order_data['order_secret'];
  210 +
  211 + return $res;
  212 + }
  213 +}