StoreAssetsController.php 24 KB

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