StoreAssetsController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <?php
  2. namespace addons\Store\backend\controllers;
  3. use addons\Store\common\logic\order\OrderCommissionLogic;
  4. use addons\Store\common\models\Store;
  5. use addons\Store\common\models\StoreCommission;
  6. use addons\Store\common\models\StoreOrder;
  7. use common\enums\AddonsEnum;
  8. use common\enums\DownloadEnum;
  9. use common\enums\StatusEnum;
  10. use common\helpers\ArrayHelper;
  11. use common\helpers\csv\CsvExportHelper;
  12. use common\models\common\CapitalLog;
  13. use common\models\common\CommissionLog;
  14. use common\models\mall\MallAddons;
  15. use common\models\user\User;
  16. class StoreAssetsController extends BaseController
  17. {
  18. public function actionIndex()
  19. {
  20. if (!\Yii::$app->request->isAjax) {
  21. return $this->render('/store-assets/index');
  22. }
  23. if (\Yii::$app->request->isGet) {
  24. $tabname = \Yii::$app->request->get('tabname');
  25. if (empty($tabname) || !in_array($tabname, ['order-detail', 'cashier','platform-store-clerk','secondary_card'])) {
  26. return $this->error('参数错误: tabname');
  27. }
  28. if ('order-detail' == $tabname || 'platform-store-clerk' == $tabname) {
  29. $type = $tabname == 'order-detail' ? 1 : 3;
  30. return $this->orderDetailList($type);
  31. } else if('cashier' == $tabname) {
  32. return $this->cashierList();
  33. } else if('secondary_card' == $tabname) {
  34. return $this->secondaryCardList();
  35. }
  36. }
  37. if (\Yii::$app->request->post('flag') == 'EXPORT') {
  38. $post = \Yii::$app->request->post();
  39. $post['mall_id'] = $this->mall_id;
  40. $filename = '平台-门店收银台资产明细列表-' . date('YmdHis') . '_' . rand(10000, 99999);
  41. $method = 'exportHandle';
  42. $type = DownloadEnum::TYPE_STORE_CASHIER;
  43. if ($post['activityTab'] == 'order-detail') {
  44. $filename = '平台-门店订单明细列表-' . date('YmdHis') . '_' . rand(10000, 99999);
  45. $method = 'orderDetailExportHandle';
  46. $type = DownloadEnum::TYPE_ASSETS;
  47. }
  48. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, $type, StoreCommission::class, $method, $post);
  49. if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
  50. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  51. }
  52. }
  53. /**
  54. * @name:
  55. * @msg: 门店订单明细
  56. * @param {*}
  57. * @return {*}
  58. */
  59. private function orderDetailList($type = 1)
  60. {
  61. $page = \Yii::$app->request->get('page', 1);
  62. $limit = \Yii::$app->request->get('limit', $this->pageSize);
  63. $store_name = \Yii::$app->request->get('store_name');
  64. $user_id = \Yii::$app->request->get('user_id');
  65. $nickname = \Yii::$app->request->get('nickname');
  66. $mobile = \Yii::$app->request->get('mobile');
  67. $order_no = \Yii::$app->request->get('order_no');
  68. $order_status = \Yii::$app->request->get('order_status');
  69. if (!in_array($order_status, [0, 1, 2, 3])) {
  70. return $this->error('参数错误:order_status');
  71. }
  72. $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => $type];
  73. $stores = [];
  74. if (!empty($store_name)) {
  75. $stores = Store::find()
  76. ->select('id,store_name,logo_img')
  77. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  78. ->andWhere(['like', 'store_name', $store_name])
  79. ->asArray()
  80. ->indexBy('id')
  81. ->all();
  82. $store_ids = array_column($stores, 'id');
  83. $wheres[] = ['store_id' => $store_ids];
  84. }
  85. if (!empty($user_id)) {
  86. $wheres[] = ['user_id' => $user_id];
  87. }
  88. $user_wheres = [];
  89. $users = [];
  90. if (!empty($nickname)) {
  91. $user_wheres[] = ['like', 'nickname', $nickname];
  92. }
  93. if (!empty($mobile)) {
  94. $user_wheres[] = ['like', 'mobile', $mobile];
  95. }
  96. if (!empty($user_wheres)) {
  97. $user_wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED];
  98. $query = User::find()->select('id,nickname,mobile,avatar_url');
  99. foreach ($user_wheres as $where) {
  100. $query->andWhere($where);
  101. }
  102. $users = $query->asArray()->indexBy('id')->all();
  103. $user_ids = array_column($users, 'id');
  104. $wheres[] = ['user_id' => $user_ids];
  105. }
  106. if (!empty($order_no)) {
  107. $wheres[] = ['like', 'order_no', $order_no];
  108. }
  109. if (!empty($order_status)) {
  110. if (1 == $order_status) {
  111. $wheres[] = ['is_settlement' => 0];
  112. } elseif (2 == $order_status) {
  113. $wheres[] = ['is_settlement' => 1];
  114. } else {
  115. $wheres[] = ['!=', 'status', StatusEnum::ENABLED];
  116. }
  117. }
  118. $params = [
  119. 'select' => 'id,mall_id,store_id,user_id,order_no,order_money,pay_money,discount_money,addons_bonus,service_charge,amount_received,is_settlement,created_at,status,store_send_commission,store_agent_send_commission',
  120. 'where' => $wheres,
  121. 'order' => 'created_at desc',
  122. 'page' => $page,
  123. 'limit' => $limit
  124. ];
  125. $log_list = StoreCommission::listPage($params);
  126. $log_list['orderDetailFieldsList'] = StoreCommission::orderDetailFieldsList();
  127. if (empty($log_list['list'])) {
  128. if (false === $log_list['list']) {
  129. return $this->error(StoreCommission::getStaticError());
  130. }
  131. return $this->success('success', $log_list);
  132. }
  133. if (empty($stores)) {
  134. $store_ids = array_column($log_list['list'], 'store_id');
  135. $stores = Store::find()
  136. ->select('id,store_name,logo_img')
  137. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  138. ->andWhere(['like', 'store_name', $store_name])
  139. ->asArray()
  140. ->indexBy('id')
  141. ->all();
  142. }
  143. if (empty($users)) {
  144. $user_ids = array_column($log_list['list'], 'user_id');
  145. $users = User::find()
  146. ->select('id,nickname,mobile,avatar_url')
  147. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $user_ids])
  148. ->asArray()
  149. ->indexBy('id')
  150. ->all();
  151. }
  152. foreach ($log_list['list'] as &$list) {
  153. $store = $stores[$list['store_id']] ?? [];
  154. $user = $users[$list['user_id']] ?? [];
  155. $list['nickname'] = $user['nickname'] ?? '';
  156. $list['mobile'] = $user['mobile'] ?? '';
  157. $list['avatar_url'] = !empty($user['avatar_url']) ? $user['avatar_url'] : \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
  158. $list['store_name'] = $store['store_name'] ?? '';
  159. $list['store_logo'] = $store['logo_img'] ?? \Yii::$app->request->hostInfo . '/resources/img/common/o2o-store-default-logo.png';
  160. if ($list['status'] != StatusEnum::ENABLED) {
  161. $list['settle_status'] = 3;
  162. } else {
  163. if ($list['is_settlement'] == 0) {
  164. $list['settle_status'] = 1;
  165. } else {
  166. $list['settle_status'] = 2;
  167. }
  168. }
  169. }
  170. $total_order_amounts = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => $type])->sum('order_money');
  171. $settle_order_amounts = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED,'is_settlement'=>1, 'type' => $type])->sum('amount_received');
  172. $not_settle_order_amounts = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED,'is_settlement'=>0, 'type' => $type])->sum('amount_received');
  173. if(empty($total_order_amounts)) $total_order_amounts = 0;
  174. if(empty($settle_order_amounts)) $settle_order_amounts = 0;
  175. if(empty($not_settle_order_amounts)) $not_settle_order_amounts = 0;
  176. $log_list['total_order_amounts'] = round($total_order_amounts, 2);
  177. $log_list['settle_order_amounts'] = round($settle_order_amounts, 2);
  178. $log_list['not_settle_order_amounts'] = round($not_settle_order_amounts, 2);
  179. $log_list['install_platform_store_clerk'] = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_PLATFORM_STORE_CLERK) ? 1 : 0;
  180. $log_list['install_secondary_card'] = MallAddons::isInstall($this->mall_id, 'SecondaryCard') ? 1 : 0;
  181. return $this->success('success', $log_list);
  182. }
  183. // 收银台收入明细
  184. private function cashierList()
  185. {
  186. $page = \Yii::$app->request->get('page', 1);
  187. $limit = \Yii::$app->request->get('limit', $this->pageSize);
  188. $min_amount = \Yii::$app->request->get('min_amount');
  189. $max_amount = \Yii::$app->request->get('max_amount');
  190. $start_time = \Yii::$app->request->get('start_time');
  191. $end_time = \Yii::$app->request->get('end_time');
  192. $store_name = \Yii::$app->request->get('store_name');
  193. $user_id = \Yii::$app->request->get('user_id');
  194. $nickname = \Yii::$app->request->get('nickname');
  195. $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => 2];
  196. if (!empty($min_amount)) {
  197. $wheres[] = ['>=', 'pay_money', $min_amount];
  198. }
  199. if (!empty($max_amount)) {
  200. $wheres[] = ['<=', 'pay_money', $max_amount];
  201. }
  202. if (!empty($start_time)) {
  203. $wheres[] = ['>=', 'created_at', $start_time];
  204. }
  205. if (!empty($end_time)) {
  206. $wheres[] = ['<=', 'created_at', $end_time];
  207. }
  208. if (!empty($store_name)) {
  209. $stores = Store::find()
  210. ->select('id,store_name,logo_img')
  211. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  212. ->andWhere(['like', 'store_name', $store_name])
  213. ->asArray()
  214. ->indexBy('id')
  215. ->all();
  216. $store_ids = array_column($stores, 'id');
  217. $wheres[] = ['store_id' => $store_ids];
  218. }
  219. if (!empty($user_id)) {
  220. $wheres[] = ['user_id' => $user_id];
  221. }
  222. $user_wheres = [];
  223. $users = [];
  224. if (!empty($nickname)) {
  225. $user_wheres[] = ['like', 'nickname', $nickname];
  226. }
  227. if (!empty($mobile)) {
  228. $user_wheres[] = ['like', 'mobile', $mobile];
  229. }
  230. if (!empty($user_wheres)) {
  231. $user_wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED];
  232. $query = User::find()->select('id,nickname,mobile,avatar_url');
  233. foreach ($user_wheres as $where) {
  234. $query->andWhere($where);
  235. }
  236. $users = $query->asArray()->indexBy('id')->all();
  237. $user_ids = array_column($users, 'id');
  238. $wheres[] = ['user_id' => $user_ids];
  239. }
  240. $params = [
  241. 'select' => 'id,mall_id,store_id,user_id,order_no,order_money,pay_money,discount_money,amount_received,is_settlement,service_charge,created_at',
  242. 'where' => $wheres,
  243. 'order' => 'created_at desc',
  244. 'page' => $page,
  245. 'limit' => $limit,
  246. ];
  247. // dd($params);
  248. $commission_logs = StoreCommission::listPage($params);
  249. if (false === $commission_logs['list']) {
  250. return $this->error(StoreCommission::getStaticError());
  251. }
  252. if (!empty($commission_logs['list'])) {
  253. if (empty($users)) {
  254. $user_ids = array_column($commission_logs['list'], 'user_id');
  255. $users = User::find()
  256. ->select('id,nickname,mobile,avatar_url')
  257. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $user_ids])
  258. ->asArray()
  259. ->indexBy('id')
  260. ->all();
  261. }
  262. if (empty($stores)) {
  263. $store_ids = array_column($commission_logs['list'], 'store_id');
  264. $stores = Store::find()
  265. ->select('id,store_name,logo_img')
  266. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $store_ids])
  267. ->andWhere(['like', 'store_name', $store_name])
  268. ->asArray()
  269. ->indexBy('id')
  270. ->all();
  271. }
  272. foreach ($commission_logs['list'] as &$log) {
  273. $user = $users[$log['user_id']] ?? [];
  274. $store = $stores[$log['store_id']] ?? [];
  275. $log['nickname'] = $user['nickname'] ?? '';
  276. $log['nickname'] = $user['nickname'] ?? '';
  277. $log['avatar_url'] = !empty($user['avatar_url']) ? $user['avatar_url'] : \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
  278. $log['mobile'] = $user['mobile'] ?? '';
  279. $log['store_name'] = $store['store_name'] ?? '';
  280. $log['logo_img'] = $store['logo_img'] ?? '';
  281. }
  282. }
  283. $total_real_pay_amounts = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => 2])->sum('order_money');
  284. $total_order_numbers = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => 2])->count();
  285. $total_receive_amounts = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => 2])->sum('amount_received');
  286. if(empty($total_real_pay_amounts)) $total_real_pay_amounts = 0;
  287. if(empty($total_receive_amounts)) $total_receive_amounts = 0;
  288. if(empty($total_order_numbers)) $total_order_numbers = 0;
  289. $commission_logs['total_real_pay_amounts'] = round($total_real_pay_amounts, 2);
  290. $commission_logs['total_receive_amounts'] = round($total_receive_amounts, 2);
  291. $commission_logs['total_order_numbers'] = $total_order_numbers;
  292. // 导出字段列表
  293. $export_fields = StoreCommission::fieldsList();
  294. $commission_logs['export_list'] = $export_fields;
  295. $commission_logs['install_platform_store_clerk'] = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_PLATFORM_STORE_CLERK) ? 1 : 0;
  296. return $this->success('success', $commission_logs);
  297. }
  298. private function secondaryCardList()
  299. {
  300. $page = \Yii::$app->request->get('page', 1);
  301. $limit = \Yii::$app->request->get('limit', $this->pageSize);
  302. $store_name = \Yii::$app->request->get('store_name');
  303. $user_id = \Yii::$app->request->get('user_id');
  304. $nickname = \Yii::$app->request->get('nickname');
  305. $mobile = \Yii::$app->request->get('mobile');
  306. $order_no = \Yii::$app->request->get('order_no');
  307. $order_status = \Yii::$app->request->get('order_status');
  308. if (!in_array($order_status, [0, 1, 2, 3])) {
  309. return $this->error('参数错误:order_status');
  310. }
  311. $type = 4;
  312. $wheres[] = ['mall_id' => $this->mall_id, ];
  313. $wheres[] = ['status' => StatusEnum::ENABLED];
  314. $wheres[] = [ 'type' => $type];
  315. $stores = [];
  316. if (!empty($store_name)) {
  317. $stores = Store::find()
  318. ->select('id,store_name,logo_img')
  319. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  320. ->andWhere(['like', 'store_name', $store_name])
  321. ->asArray()
  322. ->indexBy('id')
  323. ->all();
  324. $store_ids = array_column($stores, 'id');
  325. $wheres[] = ['store_id' => $store_ids];
  326. }
  327. if (!empty($user_id)) {
  328. $wheres[] = ['user_id' => $user_id];
  329. }
  330. $user_wheres = [];
  331. $users = [];
  332. if (!empty($nickname)) {
  333. $user_wheres[] = ['like', 'nickname', $nickname];
  334. }
  335. if (!empty($mobile)) {
  336. $user_wheres[] = ['like', 'mobile', $mobile];
  337. }
  338. if (!empty($user_wheres)) {
  339. $user_wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED];
  340. $query = User::find()->select('id,nickname,mobile,avatar_url');
  341. foreach ($user_wheres as $where) {
  342. $query->andWhere($where);
  343. }
  344. $users = $query->asArray()->indexBy('id')->all();
  345. $user_ids = array_column($users, 'id');
  346. $wheres[] = ['user_id' => $user_ids];
  347. }
  348. if (!empty($order_no)) {
  349. $wheres[] = ['like', 'order_no', $order_no];
  350. }
  351. if (!empty($order_status)) {
  352. if (1 == $order_status) {
  353. $wheres[] = ['is_settlement' => 0];
  354. } elseif (2 == $order_status) {
  355. $wheres[] = ['is_settlement' => 1];
  356. } else {
  357. $wheres[] = ['!=', 'status', StatusEnum::ENABLED];
  358. }
  359. }
  360. $params = [
  361. 'select' => 'id,mall_id,type,store_id,user_id,order_no,order_money,pay_money,discount_money,addons_bonus,service_charge,amount_received,is_settlement,created_at,status,store_send_commission,store_agent_send_commission',
  362. 'where' => $wheres,
  363. 'order' => 'created_at desc',
  364. 'page' => $page,
  365. 'limit' => $limit
  366. ];
  367. $log_list = StoreCommission::listPage($params);
  368. if (empty($log_list['list'])) {
  369. if (false === $log_list['list']) {
  370. return $this->error(StoreCommission::getStaticError());
  371. }
  372. return $this->success('success', $log_list);
  373. }
  374. if (empty($stores)) {
  375. $store_ids = array_column($log_list['list'], 'store_id');
  376. $stores = Store::find()
  377. ->select('id,store_name,logo_img')
  378. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  379. ->andWhere(['like', 'store_name', $store_name])
  380. ->asArray()
  381. ->indexBy('id')
  382. ->all();
  383. }
  384. if (empty($users)) {
  385. $user_ids = array_column($log_list['list'], 'user_id');
  386. $users = User::find()
  387. ->select('id,nickname,mobile,avatar_url')
  388. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $user_ids])
  389. ->asArray()
  390. ->indexBy('id')
  391. ->all();
  392. }
  393. foreach ($log_list['list'] as &$list) {
  394. $store = $stores[$list['store_id']] ?? [];
  395. $user = $users[$list['user_id']] ?? [];
  396. $list['nickname'] = $user['nickname'] ?? '';
  397. $list['mobile'] = $user['mobile'] ?? '';
  398. $list['avatar_url'] = !empty($user['avatar_url']) ? $user['avatar_url'] : \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
  399. $list['store_name'] = $store['store_name'] ?? '';
  400. $list['store_logo'] = $store['logo_img'] ?? \Yii::$app->request->hostInfo . '/resources/img/common/o2o-store-default-logo.png';
  401. }
  402. $total_order_amounts = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => $type])->sum('order_money');
  403. $settle_order_amounts = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED,'is_settlement'=>1, 'type' => $type])->sum('amount_received');
  404. $not_settle_order_amounts = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED,'is_settlement'=>0, 'type' => $type])->sum('amount_received');
  405. if(empty($total_order_amounts)) $total_order_amounts = 0;
  406. if(empty($settle_order_amounts)) $settle_order_amounts = 0;
  407. if(empty($not_settle_order_amounts)) $not_settle_order_amounts = 0;
  408. $log_list['total_order_amounts'] = round($total_order_amounts, 2);
  409. $log_list['settle_order_amounts'] = round($settle_order_amounts, 2);
  410. $log_list['not_settle_order_amounts'] = round($not_settle_order_amounts, 2);
  411. $log_list['install_secondary_card'] = MallAddons::isInstall($this->mall_id, 'SecondaryCard') ? 1 : 0;
  412. return $this->success('success', $log_list);
  413. }
  414. /**
  415. * @name:
  416. * @msg: 获取插件分佣金额
  417. * @return {*}
  418. */
  419. public function actionAddonsCommission()
  420. {
  421. if (!\Yii::$app->request->isGet) {
  422. return $this->error('请求方式错误');
  423. }
  424. $id = \Yii::$app->request->get('id');
  425. $user_id = \Yii::$app->request->get('user_id');
  426. $order_no = \Yii::$app->request->get('order_no');
  427. $is_settlement = \Yii::$app->request->get('is_settlement');
  428. if (
  429. empty($id) ||
  430. empty($user_id) ||
  431. empty($order_no) ||
  432. !isset($is_settlement)
  433. ) {
  434. return $this->error('参数错误');
  435. }
  436. $addons_name_map = AddonsEnum::getAddonsNameMap();
  437. $result = [
  438. 'Agent' => ['name' => $addons_name_map['Agent'], 'value' => 0],
  439. 'Area' => ['name' => $addons_name_map['Area'], 'value' => 0],
  440. // 'Boss' => ['name' => $addons_name_map['Boss'], 'value' => 0],
  441. 'Distribution' => ['name' => $addons_name_map['Distribution'], 'value' => 0],
  442. 'Rebate' => ['name' => $addons_name_map['Rebate'], 'value' => 0],
  443. ];
  444. $log = StoreCommission::find()
  445. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $id, 'user_id' => $user_id, 'order_no' => $order_no, 'is_settlement' => $is_settlement])
  446. ->one();
  447. if (empty($log)) {
  448. return $this->success('success111', $result);
  449. }
  450. $order = StoreOrder::findOne(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'user_id' => $user_id, 'order_no' => $order_no]);
  451. $order_detail = $order->detail;
  452. $order_detail_ids = array_column(ArrayHelper::toArray($order_detail), 'id');
  453. CapitalLog::$capitalType = 'commission_frozen';
  454. $commission_frozen_logs = CapitalLog::find()
  455. ->where(['mall_id' => $this->mall_id, 'source_table' => 'store_order_detail', 'source_table_id' => $order_detail_ids])
  456. ->asArray()
  457. ->all();
  458. if (!empty($commission_frozen_logs)) {
  459. foreach ($commission_frozen_logs as $flog) {
  460. if ($flog['status'] != 0) {
  461. continue;
  462. }
  463. if (!isset($result[$flog['from_type']]['value'])) {
  464. $result[$flog['from_type']]['value'] = 0;
  465. }
  466. $result[$flog['from_type']]['name'] = $addons_name_map[$flog['from_type']];
  467. $result[$flog['from_type']]['value'] += $flog['change_num'] ?? 0;
  468. }
  469. }
  470. CapitalLog::$capitalType = 'commission';
  471. $commission_logs = CapitalLog::find()
  472. ->where(['mall_id' => $this->mall_id, 'source_table' => 'store_order_detail', 'source_table_id' => $order_detail_ids])
  473. ->asArray()
  474. ->all();
  475. if (!empty($commission_logs)) {
  476. foreach ($commission_logs as $log) {
  477. if (!isset($result[$log['from_type']]['value'])) {
  478. $result[$log['from_type']]['value'] = 0;
  479. }
  480. $result[$log['from_type']]['name'] = $addons_name_map[$log['from_type']];
  481. $result[$log['from_type']]['value'] += $log['change_num'] ?? 0;
  482. }
  483. }
  484. foreach ($result as &$rst) {
  485. $rst['value'] = round($rst['value'], 2);
  486. }
  487. //加上股东
  488. $store_order_commission = OrderCommissionLogic::getOrderAddonsCommission($order->id);
  489. if($store_order_commission && isset($store_order_commission['Boss'])){
  490. $result['Boss'] = ['name' => $addons_name_map['Boss'], 'value' => 0];
  491. foreach($store_order_commission['Boss'] as $info){
  492. $result['Boss']['value'] = bcadd($result['Boss']['value'],$info['commission'],2);
  493. }
  494. }
  495. if($store_order_commission && isset($store_order_commission['Rebate'])){
  496. $result['Rebate'] = ['name' => $addons_name_map['Rebate'], 'value' => 0];
  497. foreach($store_order_commission['Rebate'] as $info){
  498. $result['Rebate']['value'] = bcadd($result['Rebate']['value'],$info['commission'],2);
  499. }
  500. }
  501. return $this->success('success222', $result);
  502. }
  503. }