企微短剧业务系统

OrderService.php 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <?php
  2. namespace App\Service;
  3. use App\Log;
  4. use App\Models\AuthorizeCorp;
  5. use App\Models\Customer;
  6. use App\Models\DjOrder;
  7. use App\Models\DjUser;
  8. use App\Models\ExportTask;
  9. use App\Models\OfficialAccount;
  10. use App\Models\OfficialWebUserActionSetId;
  11. use App\Models\OperateLog;
  12. use App\Models\OrderShareInProportionConf;
  13. use App\Models\OrderSummary;
  14. use App\Models\System\Users;
  15. use App\Models\TencentAdAuth;
  16. use App\RedisModel;
  17. use App\Service\Order\ChuMoService;
  18. use App\Support\EmailQueue;
  19. use PhpOffice\PhpSpreadsheet\IOFactory;
  20. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  21. class OrderService
  22. {
  23. public static function dataStatSecond($params)
  24. {
  25. $orderModel = DjOrder::getOrderQuery($params);
  26. # 获取统计数据
  27. $statData = $orderModel->selectRaw("count(1) as order_count, count(distinct(external_userid)) as pay_uv, "
  28. ." count(external_userid) as pay_pv, sum(pay_money) as pay_money, sum(origin_pay_money) as origin_pay_money")
  29. ->first();
  30. $statData->pay_money = round($statData->pay_money / 10000, 4);
  31. $statData->order_count = intval($statData->order_count);
  32. $statData->pay_uv = intval($statData->pay_uv);
  33. $statData->pay_pv = intval($statData->pay_pv);
  34. $statData->origin_pay_money = round($statData->origin_pay_money / 10000, 2);
  35. return ['stat' => $statData, 'trend' => []];
  36. }
  37. /**
  38. * 订单列表
  39. * */
  40. public static function getOrderList($params, $corpid, $page, $pageSize)
  41. {
  42. list($list, $count) = DjOrder::getOrderList($params, $page, $pageSize);
  43. # 获取公众号信息
  44. $appIdList = $list->pluck('bind_app_id');
  45. $appList = OfficialAccount::select(['mp_name', 'mp_app_id'])->whereIn('mp_app_id', $appIdList)->get();
  46. # 获取客户信息
  47. $userIds = $list->pluck('external_userid');
  48. $userList = Customer::suffix($corpid)->select(['external_userid', 'avatar', 'name', 'id'])
  49. ->where('corpid', $corpid)
  50. ->whereIn('external_userid', $userIds)
  51. ->get();
  52. # 回传枚举数据
  53. $adReportActionType = DjOrder::AD_REPORT_ACTION_TYPE;
  54. $adReportOrderStatus = DjOrder::AD_REPORT_ORDER_STATUS;
  55. $adReportPurchaseStatus = DjOrder::AD_REPORT_PURCHASE_STATUS;
  56. $adReportOrderRules = DjOrder::AD_REPORT_ORDER_RULES;
  57. $channelArr = config('jiashu.channel');
  58. # 订单来源
  59. $orderSource = config('platform.base');
  60. // $orderSource = DjOrder::ORDER_SOURCE;
  61. foreach ($list as $datum) {
  62. # 公众号信息补充
  63. $wxAccountInfo = $appList->where('mp_app_id', $datum->bind_app_id)->first();
  64. $wxAccountName = isset($wxAccountInfo->mp_name) ? $wxAccountInfo->mp_name : null;
  65. $wxAccountName = !empty($wxAccountName) ? $wxAccountName : (isset($channelArr[$datum->channel]) ? $channelArr[$datum->channel] : '-');
  66. $datum->wx_account = $wxAccountName;
  67. # 用户信息补充
  68. $userInfo = $userList->where('external_userid', $datum->external_userid)->first();
  69. $datum->name = isset($userInfo->name) ? $userInfo->name : '';
  70. $datum->customer_id = isset($userInfo->id) ? $userInfo->id : '';
  71. # 订单金额处理
  72. $datum->pay_money = round($datum->pay_money / 10000, 4);
  73. # 实际订单金额处理
  74. $datum->origin_pay_money = round($datum->origin_pay_money / 10000, 2);
  75. # 订单回传状态(下单以及付费回传任何一个成功即可算作成功)
  76. $datum->ad_report_status = ($datum->ad_report_order_status == 1) ? 1 :
  77. (($datum->ad_report_purchase_status == 1) ? 1 : 0);
  78. # 回传类型
  79. $datum->ad_report_action_type = isset($adReportActionType[$datum->ad_report_action_type]) ? $adReportActionType[$datum->ad_report_action_type] : $datum->ad_report_action_type;
  80. # 订单回传结果
  81. $datum->ad_report_order_status = isset($adReportOrderStatus[$datum->ad_report_order_status]) ? $adReportOrderStatus[$datum->ad_report_order_status] : $datum->ad_report_order_status;
  82. # 订单回传规则
  83. $datum->ad_report_order_rules = isset($adReportOrderRules[$datum->ad_report_order_rules]) ? $adReportOrderRules[$datum->ad_report_order_rules] : $datum->ad_report_order_rules;
  84. # 全量回传结果
  85. $datum->ad_report_purchase_status = isset($adReportPurchaseStatus[$datum->ad_report_purchase_status]) ? $adReportPurchaseStatus[$datum->ad_report_purchase_status] : $datum->ad_report_purchase_status;
  86. # 订单来源
  87. $datum->order_source = isset($orderSource[$datum->order_source]) ? $orderSource[$datum->order_source] : $datum->order_source;
  88. # 用户关注时间
  89. $datum->mp_user_register_time = !empty($datum->mp_user_register_time) ? date('Y-m-d H:i:s', substr($datum->mp_user_register_time, 0, 10)) : null;
  90. # 下单时间
  91. $datum->order_pay_time = date('Y-m-d H:i:s', substr($datum->order_pay_time, 0, 10));
  92. # 投放账号
  93. if(1 == $datum->order_type) {
  94. $datum->launch_account = $datum->wx_account;
  95. } else {
  96. $datum->launch_account = $datum->adq_account_id;
  97. }
  98. # 支付类型
  99. $datum->pay_type = $datum->pay_type == 1 ? '小程序虚拟支付' : '其他类型支付';
  100. }
  101. return [$list, $count];
  102. }
  103. public static function actionUpload($orderId, $orderDataId, &$errcode)
  104. {
  105. try{
  106. # 判断订单是否已经上报
  107. $orderInfo = DjOrder::query()->where('order_id', $orderId)->where(function($query) use ($orderDataId) {
  108. if($orderDataId) $query->where('id', $orderDataId);
  109. })->first();
  110. if(empty($orderInfo)) {
  111. $errcode = 3801;// 订单ID不合法
  112. return false;
  113. }
  114. $reportStatus = ($orderInfo->ad_report_order_status == 1) ? 1 :
  115. (($orderInfo->ad_report_purchase_status == 1) ? 1 : 0);
  116. if(1 == $reportStatus) {
  117. $errcode = 3802;// 已经上报过了
  118. return false;
  119. }
  120. # 更新订单投放账号对应的数据源id(防止由于数据源id错误导致回传失败)
  121. $adqAccountId = $orderInfo->adq_account_id;
  122. if(!empty($adqAccountId)) {
  123. $userActionSetId = OfficialWebUserActionSetId::query()->where('account_id', $adqAccountId)
  124. ->where('enable', 1)->value('web_user_action_set_id');
  125. if(!empty($userActionSetId) && $userActionSetId != $orderInfo->bind_user_action_set_id){
  126. DjOrder::query()->where('order_id', $orderId)->update(['bind_user_action_set_id' => $userActionSetId]);
  127. $orderInfo->bind_user_action_set_id = $userActionSetId;
  128. }
  129. }
  130. # 信息放入带处理队列中
  131. $orderArr = array_merge($orderInfo->toArray(), ['ignore_black' => 1]);
  132. TencentAdAuth::intoActionAddList($orderArr);
  133. $errcode = 0;
  134. return true;
  135. } catch (\Exception $exception) {
  136. Log::logError('手动订单回传程序异常', [
  137. 'order_id' => $orderId,
  138. 'message' => $exception->getFile().'('.$exception->getLine().'):'.$exception->getMessage(),
  139. 'trace' => $exception->getTraceAsString()
  140. ], 'interface');
  141. EmailQueue::rPush('手动订单回传程序异常', json_encode([
  142. 'order_id' => $orderId,
  143. 'message' => $exception->getFile().'('.$exception->getLine().'):'.$exception->getMessage()
  144. ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
  145. return false;
  146. }
  147. }
  148. public static function orderExport($params, &$errcode)
  149. {
  150. ini_set('memory_limit', '2048M');
  151. set_time_limit(0);
  152. # 防止重复点击
  153. $key = 'Playlet::orderExport-'.json_encode($params, 1);
  154. $val = RedisModel::get($key);
  155. if($val) {
  156. $errcode = 2007;
  157. return ;
  158. } else {
  159. RedisModel::set($key, 1);
  160. RedisModel::expire($key, 10);
  161. }
  162. try{
  163. $spreadsheet = new Spreadsheet();
  164. $sheet = $spreadsheet->getActiveSheet();
  165. $row_index = 1;
  166. $column_index = 1;
  167. /**设置标题**/
  168. $title = ['订单ID', '企微主体', '公众号', '用户ID', '小程序注册时间', '企微用户关注时间', '是否首单', '下单时间', '下单金额'
  169. , '分成后订单金额', '支付类型', '订单来源', '剧名', '登录账号', '推广链接', '推广类型'];
  170. foreach ($title as $name){
  171. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,$name);
  172. }
  173. // 只展示已支付订单
  174. $params['pay_status'] = 1;
  175. list($list, $count) = DjOrder::getOrderList($params, 1, 100000);
  176. # 获取公众号信息
  177. $appList = OfficialAccount::query()->select(['mp_name', 'mp_app_id'])->get();
  178. # 获取企微信息
  179. $corpList = AuthorizeCorp::query()->select(['corpid', 'corp_name'])->get();
  180. # 订单来源
  181. $orderSource = config('platform.base');
  182. $channelArr = config('jiashu.channel');
  183. foreach ($list as $datum) {
  184. $row_index++;
  185. $column_index=1; //重置列索引
  186. # 公众号信息补充
  187. $wxAccountInfo = $appList->where('mp_app_id', $datum->bind_app_id)->first();
  188. $wxAccountName = isset($wxAccountInfo->mp_name) ? $wxAccountInfo->mp_name : null;
  189. $wxAccountName = !empty($wxAccountName) ? $wxAccountName : (isset($channelArr[$datum->channel]) ? $channelArr[$datum->channel] : '-');
  190. $datum->wx_account = $wxAccountName;
  191. # 企微信息
  192. $corpInfo = $corpList->where('corpid', $datum->system_corpid)->first();
  193. $datum->corp_name = isset($corpInfo->corp_name) ? $corpInfo->corp_name : '-';
  194. # 订单金额处理
  195. $datum->pay_money = round($datum->pay_money / 10000, 4);
  196. # 实际订单金额处理
  197. $datum->origin_pay_money = round($datum->origin_pay_money / 10000, 2);
  198. # 订单来源
  199. $datum->order_source = isset($orderSource[$datum->order_source]) ? $orderSource[$datum->order_source] : $datum->order_source;
  200. # 用户关注时间
  201. $maUserRegisterTime = !empty($datum->ma_user_register_time) ? date('Y-m-d H:i:s', substr($datum->ma_user_register_time, 0, 10)) : '';
  202. $datum->ma_user_register_time = $maUserRegisterTime;
  203. # 下单时间
  204. $datum->order_pay_time = date('Y-m-d H:i:s', substr($datum->order_pay_time, 0, 10));
  205. # 是否首单
  206. $datum->first_order = $datum->first_order_status == 1 ? '是' : ($datum->first_order_status == 2 ? '否' : '未知');
  207. # 投放来源
  208. $datum->plat_order_type = $datum->plat_order_type == 1 ? 'h5' : '小程序';
  209. # 支付类型
  210. $datum->pay_type = $datum->pay_type == 1 ? '小程序虚拟支付' : '其他类型支付';
  211. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,"'".$datum->order_id);
  212. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,$datum->corp_name);
  213. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,$datum->wx_account);
  214. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,$datum->user_id);
  215. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,$datum->ma_user_register_time);
  216. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,$datum->first_order);
  217. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,$datum->order_pay_time);
  218. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,$datum->origin_pay_money);
  219. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,$datum->pay_money);
  220. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,$datum->pay_type);
  221. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,$datum->order_source);
  222. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,$datum->playlet_name);
  223. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,$datum->login_account);
  224. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,$datum->promotion_title);
  225. $sheet->setCellValueByColumnAndRow($column_index++,$row_index,$datum->plat_order_type);
  226. }
  227. $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
  228. header('Content-Type:application/vnd.ms-excel');
  229. header('Content-Disposition:attachment;filename=订单导出.xlsx');
  230. header('Cache-Control:max-age=0');
  231. $writer->save('php://output');
  232. } catch (\Exception $exception) {
  233. Log::logError('订单导出异常', [
  234. 'params' => $params,
  235. 'file' => $exception->getFile(),
  236. 'line' => $exception->getLine(),
  237. 'message' => $exception->getMessage(),
  238. 'trace' => $exception->getTraceAsString(),
  239. ], 'OrderExportException');
  240. EmailQueue::rPush('订单导出异常', json_encode([
  241. 'params' => $params,
  242. 'file' => $exception->getFile(),
  243. 'line' => $exception->getLine(),
  244. 'message' => $exception->getMessage(),
  245. 'trace' => $exception->getTraceAsString(),
  246. ], 256), ['song.shen@kuxuan-inc.com'], '猎羽');
  247. $errcode = 500;
  248. return ;
  249. }
  250. }
  251. public static function chargeFirst($orderInfo)
  252. {
  253. $flag = '否';
  254. $order = DjOrder::query()->select('order_id')->where('order_source', 2)
  255. ->where('channel', $orderInfo['channel'])->where('user_id', strval($orderInfo['user_id']))
  256. ->where('pay_status', 1)
  257. ->orderBy('order_pay_time', 'asc')->first();
  258. if(isset($order->order_id) && $order->order_id == $orderInfo['order_id']) {
  259. $flag = '是';
  260. }
  261. return $flag;
  262. }
  263. public static function orderList($params, $page, $pageSize)
  264. {
  265. // 只展示已支付订单
  266. $params['pay_status'] = 1;
  267. list($list, $count) = DjOrder::getOrderList($params, $page, $pageSize);
  268. # 获取公众号信息
  269. $appIdList = $list->pluck('bind_app_id');
  270. $appIdList = array_unique($appIdList->toArray());
  271. $appList = OfficialAccount::query()->select(['mp_name', 'mp_app_id'])->whereIn('mp_app_id', $appIdList)->get();
  272. # 获取企微信息
  273. $corpidList = $list->pluck('system_corpid');
  274. $corpidList = array_unique($corpidList->toArray());
  275. $corpList = AuthorizeCorp::query()->select(['corpid', 'corp_name'])->whereIn('corpid', $corpidList)->get();
  276. # 获取企微客服信息
  277. $corpUserList = DjUser::query()->select(['corpid', 'user_id', 'name'])->whereIn('corpid', $corpidList)->get();
  278. # 订单来源
  279. $orderSource = config('platform.base');
  280. $channelArr = config('jiashu.channel');
  281. foreach ($list as $datum) {
  282. # 公众号信息补充
  283. $wxAccountInfo = $appList->where('mp_app_id', $datum->bind_app_id)->first();
  284. $wxAccountName = isset($wxAccountInfo->mp_name) ? $wxAccountInfo->mp_name : null;
  285. $wxAccountName = !empty($wxAccountName) ? $wxAccountName : (isset($channelArr[$datum->channel]) ? $channelArr[$datum->channel] : '-');
  286. $datum->wx_account = $wxAccountName;
  287. # 企微信息
  288. $corpInfo = $corpList->where('corpid', $datum->system_corpid)->first();
  289. $datum->corp_name = isset($corpInfo->corp_name) ? $corpInfo->corp_name : '-';
  290. $userInfo = $corpUserList->where('corpid', $datum->system_corpid)->where('user_id', $datum->corp_user_id)->first();
  291. $datum->user_name = isset($userInfo->name) ? $userInfo->name : '-';
  292. # 订单金额处理
  293. $datum->pay_money = round($datum->pay_money / 10000, 4);
  294. # 实际订单金额处理
  295. $datum->origin_pay_money = round($datum->origin_pay_money / 10000, 2);
  296. # 订单来源
  297. $datum->order_source = isset($orderSource[$datum->order_source]) ? $orderSource[$datum->order_source] : $datum->order_source;
  298. # 小程序关注时间
  299. $maUserRegisterTime = !empty($datum->ma_user_register_time) ? date('Y-m-d H:i:s', substr($datum->ma_user_register_time, 0, 10))
  300. : '';
  301. $datum->ma_user_register_time = $maUserRegisterTime;
  302. # 企微用户关注时间
  303. $mpUserRegisterTime = !empty($datum->mp_user_register_time) ? date('Y-m-d H:i:s', substr($datum->mp_user_register_time, 0, 10))
  304. : '';
  305. $datum->mp_user_register_time = $mpUserRegisterTime;
  306. # 下单时间
  307. $datum->order_pay_time = date('Y-m-d H:i:s', substr($datum->order_pay_time, 0, 10));
  308. # 是否首单
  309. $datum->first_order_status = $datum->first_order_status == 1 ? '是' : ($datum->first_order_status == 2 ? '否' : '未知');
  310. # 投放来源
  311. $datum->plat_order_type = $datum->plat_order_type == 1 ? 'h5' : '小程序';
  312. # 支付类型
  313. $datum->pay_type = $datum->pay_type == 1 ? '小程序虚拟支付' : '其他类型支付';
  314. }
  315. return [$list, $count];
  316. }
  317. public static function orderExportOffline($params, &$errcode)
  318. {
  319. if(strtotime($params['end_date']) - strtotime($params['start_date']) > 31*86400) {
  320. $errcode = 3803;
  321. return ;
  322. }
  323. # 防止重复点击
  324. $key = 'Playlet::orderExportOffline-'.json_encode($params, 1);
  325. $val = RedisModel::get($key);
  326. if($val) {
  327. $errcode = 2007;
  328. return ;
  329. } else {
  330. RedisModel::set($key, 1);
  331. RedisModel::expire($key, 10);
  332. }
  333. $indexName = '充值订单';
  334. if (isset($params['corpid']) && !empty($params['corpid'])) {
  335. $corpName = AuthorizeCorp::query()->where('corpid', $params['corpid'])->value('corp_name');
  336. $indexName .= '-(企微:'.$corpName.')';
  337. }
  338. if (isset($params['order_id']) && !empty($params['order_id'])) {
  339. $indexName .= '-(订单ID:'.$params['order_id'].')';
  340. }
  341. if (isset($params['order_source']) && !empty($params['order_source'])) {
  342. $list = config('platform.base');
  343. $orderSource = $list[$params['order_source']] ?? '';
  344. $indexName .= '-(付费来源:'.$orderSource.')';
  345. }
  346. if (isset($params['start_date']) && !empty($params['start_date'])) {
  347. $indexName .= '-(起始日期:'.$params['start_date'].')';
  348. }
  349. if (isset($params['end_date']) && !empty($params['end_date'])) {
  350. $indexName .= '-(截止日期:'.$params['end_date'].')';
  351. }
  352. if (isset($params['account_id']) && !empty($params['account_id'])) {
  353. $indexName .= '-(adq账号:'.$params['account_id'].')';
  354. }
  355. if (isset($params['is_ad_user']) && is_numeric($params['is_ad_user'])) {
  356. $isAdUser = $params['is_ad_user'] == 1 ? '投放推广' : '运营推广';
  357. $indexName .= '-(收入来源:'.$isAdUser.')';
  358. }
  359. if (isset($params['plat_order_type']) && is_numeric($params['plat_order_type'])) {
  360. $platOrderType = $params['plat_order_type'] == 1 ? 'H5' : '小程序';
  361. $indexName .= '-(推广类型:'.$platOrderType.')';
  362. }
  363. if (isset($params['app_id']) && !empty($params['app_id'])) {
  364. $appName = OfficialAccount::query()->where('mp_app_id', $params['app_id'])->value('mp_name');
  365. $indexName .= '-(公众号:'.$appName.')';
  366. }
  367. if (isset($params['order_pay_type']) && !empty($params['order_pay_type'])) {
  368. if(1 == $params['order_pay_type']) {
  369. $indexName .= '(小程序虚拟支付)';
  370. } else {
  371. $indexName .= '(其他类型支付)';
  372. }
  373. }
  374. $data['index_name'] = $indexName;
  375. $data['data_type'] = 1;
  376. $data['params'] = json_encode($params, JSON_UNESCAPED_UNICODE);
  377. $data['operator_id'] = \Auth::id();
  378. $data['status'] = 1;
  379. $data['sys_group_id'] = $params['sys_group_id'];
  380. $res = ExportTask::query()->insert($data);
  381. if(!$res) {
  382. $errcode = 500;
  383. return;
  384. }
  385. }
  386. public static function orderExportList($sysGroupId, $page, $pageSize)
  387. {
  388. $offset = ($page -1) * $pageSize;
  389. $query = ExportTask::query()->where('sys_group_id', $sysGroupId)
  390. ->select(['created_at', 'index_name', 'file_url', 'status', 'operator_id']);
  391. $total = $query->count();
  392. $result = $query->orderBy('id', 'desc')
  393. ->offset($offset)
  394. ->limit($pageSize)
  395. ->get();
  396. $userData = Users::query()->get();
  397. foreach ($result as &$item) {
  398. $item->file_url = str_replace('http://', 'https://', $item->file_url);
  399. $operatorInfo = $userData->where('id', $item->operator_id)->first();
  400. $item->operator_name = $operatorInfo->name ?? null;
  401. }
  402. return [$result, $total];
  403. }
  404. # 统一获取各个平台订单金额分成比例
  405. public static function getOrderShareInProportion($orderSource) {
  406. $data = [];
  407. switch($orderSource) {
  408. case 1: // 柚子
  409. case 2: // 嘉书
  410. $data[1] = 0.88;// 安卓(小程序虚拟支付)
  411. $data[2] = 0.88;// ios(其他类型支付)
  412. break;
  413. case 3: // 迈步
  414. $data[1] = 0.80;// 安卓(小程序虚拟支付)
  415. $data[2] = 0.88;// ios(其他类型支付)
  416. break;
  417. case 4: // 点众阳光
  418. $data[1] = 0.80;// 安卓(小程序虚拟支付)
  419. $data[2] = 0.80;// ios(其他类型支付)
  420. break;
  421. case 5: // 花生
  422. $data[1] = 0.80;// 安卓(小程序虚拟支付)
  423. $data[2] = 0.85;// ios(其他类型支付)
  424. break;
  425. case 6: // 容量
  426. $data[1] = 0.84;// 安卓(小程序虚拟支付)
  427. $data[2] = 0.86;// ios(其他类型支付)
  428. break;
  429. case 7: // 九州
  430. $data[1] = 0.80;// 安卓(小程序虚拟支付)
  431. $data[2] = 0.85;// ios(其他类型支付)
  432. break;
  433. case 8: // 映客
  434. $data[1] = 0.792;// 安卓
  435. $data[2] = 0.8415;// ios
  436. break;
  437. case 9: // 触摸
  438. $data[1] = 0.80;// 安卓
  439. $data[2] = 0.85;// ios
  440. break;
  441. case 10:// 番茄
  442. $data[1] = 0.79;// 安卓
  443. $data[2] = 0.90;// ios
  444. break;
  445. }
  446. return $data;
  447. }
  448. public static function getOrderShareInProportionNew($orderSource, $playletName, $sysGroupId) {
  449. $value = RedisModel::hGet(OrderShareInProportionConf::ORDER_SHARE_IN_PROPORTION_CONF,
  450. $sysGroupId . '-' . $orderSource);
  451. if(!empty($value)) {
  452. $conf = json_decode($value, 1);
  453. } else {
  454. $conf = [];
  455. $confInfo = OrderShareInProportionConf::getConfInfo($sysGroupId, $orderSource);
  456. if(!empty($confInfo)) {
  457. $androidPercent = $confInfo->android_percent;
  458. $iosPercent = $confInfo->ios_percent;
  459. $conf = [1 => $androidPercent/100, 2 => $iosPercent/100];
  460. RedisModel::hSet(OrderShareInProportionConf::ORDER_SHARE_IN_PROPORTION_CONF,
  461. $sysGroupId . '-' . $orderSource, json_encode($conf));
  462. } else {
  463. if(3 == $sysGroupId) EmailQueue::rPush('查找订单金额分成比例配置异常', $sysGroupId.'###'.$orderSource, ['song.shen@kuxuan-inc.com'], '猎羽');
  464. }
  465. }
  466. return $conf;
  467. }
  468. # 设置第三方平台订单金额分成比例
  469. public static function setShareInProportionConf($sysGroupId, $orderSource, $androidPercent, $iosPercent, &$errcode) {
  470. # 判断分成比例是否符合预期 小数形式
  471. if($androidPercent > 100 || $androidPercent <= 0 || $iosPercent > 100 || $iosPercent <= 0) {
  472. $errcode = 3804;
  473. return false;
  474. }
  475. # 验证柚子 嘉书 点众 三个平台配置的分成比例是否一致
  476. if(in_array($orderSource, [1, 2, 4]) && $androidPercent != $iosPercent) {
  477. $errcode = 3807;
  478. return false;
  479. }
  480. # 更新数据库
  481. $con = [
  482. 'sys_group_id' => $sysGroupId,
  483. 'order_source' => $orderSource,
  484. ];
  485. $attr = [
  486. 'android_percent' => $androidPercent,
  487. 'ios_percent' => $iosPercent,
  488. 'enable' => 1,
  489. 'update_time' => date('Y-m-d H:i:s')
  490. ];
  491. $res = OrderShareInProportionConf::saveConf($con, $attr);
  492. if(!$res) {
  493. $errcode = 500;
  494. return false;
  495. }
  496. # 更新redis
  497. RedisModel::hSet(OrderShareInProportionConf::ORDER_SHARE_IN_PROPORTION_CONF,
  498. $sysGroupId . '-' . $orderSource, json_encode([1 => $androidPercent/100, 2 => $iosPercent/100]));
  499. // 记录操作日志
  500. $data = [
  501. 'sys_group_id' => $sysGroupId,
  502. 'order_source' => $orderSource,
  503. 'android_percent' => $androidPercent,
  504. 'ios_percent' => $iosPercent
  505. ];
  506. OperateLog::saveData(1, json_encode($data), \Auth::id());
  507. return true;
  508. }
  509. public static function getShareInProportionConf($sysGroupId) {
  510. $confList = OrderShareInProportionConf::getConfList($sysGroupId);
  511. $sourceList = config('platform.base');
  512. foreach($confList as $confInfo) {
  513. $orderSource = $confInfo->order_source;
  514. $sourceName = $sourceList[$orderSource] ?? '其他';
  515. $confInfo->source_name = $sourceName;
  516. }
  517. return $confList;
  518. }
  519. }