StoreAssetsController.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. namespace addons\Happiness\agent\controllers;
  3. use addons\Happiness\common\models\HappinessStore;
  4. use addons\Happiness\common\models\HappinessStoreCommission;
  5. use addons\Store\common\models\StoreCommission;
  6. use common\enums\AddonsEnum;
  7. use common\enums\DownloadEnum;
  8. use common\enums\StatusEnum;
  9. use common\helpers\csv\CsvExportHelper;
  10. use common\models\mall\MallAddons;
  11. use common\models\user\User;
  12. class StoreAssetsController extends BaseController
  13. {
  14. public function actionIndex()
  15. {
  16. if (!\Yii::$app->request->isAjax) {
  17. return $this->render('/store-assets/index');
  18. }
  19. if (\Yii::$app->request->isGet) {
  20. $type = 1;
  21. return $this->orderDetailList($type);
  22. }
  23. if (\Yii::$app->request->post('flag') == 'EXPORT') {
  24. $post = \Yii::$app->request->post();
  25. $post['mall_id'] = $this->mall_id;
  26. $filename = '平台-门店收银台资产明细列表-' . date('YmdHis') . '_' . rand(10000, 99999);
  27. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_STORE_CASHIER, StoreCommission::class, 'exportHandle', $post);
  28. if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
  29. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  30. }
  31. }
  32. private function orderDetailList($type = 1)
  33. {
  34. $page = \Yii::$app->request->get('page', 1);
  35. $limit = \Yii::$app->request->get('limit', $this->pageSize);
  36. $store_name = \Yii::$app->request->get('store_name');
  37. $user_id = \Yii::$app->request->get('user_id');
  38. $nickname = \Yii::$app->request->get('nickname');
  39. $mobile = \Yii::$app->request->get('mobile');
  40. $order_no = \Yii::$app->request->get('order_no');
  41. $order_status = \Yii::$app->request->get('order_status');
  42. if (!in_array($order_status, [0, 1, 2, 3])) {
  43. return $this->error('参数错误:order_status');
  44. }
  45. $wheres[] = ['yo.mall_id' => $this->mall_id, 'yo.status' => StatusEnum::ENABLED, 'yo.is_settlement' => [0,1]];
  46. //or条件
  47. $wheres[] = ['or', ['in', 'o.city_id', $this->city_ids], ['in', 'o.district_id', $this->district_ids], ['in',
  48. 'o.province_id', $this->province_ids]];
  49. $stores = [];
  50. if (!empty($store_name)) {
  51. $stores = HappinessStore::find()
  52. ->select('id,store_name,logo_img')
  53. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  54. ->andWhere(['like', 'store_name', $store_name])
  55. ->asArray()
  56. ->indexBy('id')
  57. ->all();
  58. $store_ids = array_column($stores, 'id');
  59. $wheres[] = ['yo.store_id' => $store_ids];
  60. }
  61. if (!empty($user_id)) {
  62. $wheres[] = ['yo.user_id' => $user_id];
  63. }
  64. $user_wheres = [];
  65. $users = [];
  66. if (!empty($nickname)) {
  67. $user_wheres[] = ['like', 'nickname', $nickname];
  68. }
  69. if (!empty($mobile)) {
  70. $user_wheres[] = ['like', 'mobile', $mobile];
  71. }
  72. if (!empty($user_wheres)) {
  73. $user_wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED];
  74. $query = User::find()->select('id,nickname,mobile,avatar_url');
  75. foreach ($user_wheres as $where) {
  76. $query->andWhere($where);
  77. }
  78. $users = $query->asArray()->indexBy('id')->all();
  79. $user_ids = array_column($users, 'id');
  80. $wheres[] = ['yo.user_id' => $user_ids];
  81. }
  82. if (!empty($order_no)) {
  83. $wheres[] = ['like', 'yo.order_no', $order_no];
  84. }
  85. if (!empty($order_status)) {
  86. if (1 == $order_status) {
  87. $wheres[] = ['yo.is_settlement' => 0];
  88. } elseif (2 == $order_status) {
  89. $wheres[] = ['yo.is_settlement' => 1];
  90. } else {
  91. $wheres[] = ['!=', 'status', StatusEnum::ENABLED];
  92. }
  93. }
  94. $join = [['LEFT JOIN', HappinessStore::tableName(). ' as o', "o.id = yo.store_id"]];
  95. $params = [
  96. // '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',
  97. 'where' => $wheres,
  98. 'order' => 'yo.created_at desc',
  99. 'page' => $page,
  100. 'limit' => $limit,
  101. 'join'=>$join,
  102. 'select'=>'yo.*,o.city_id,o.province_id,o.district_id,o.store_name,o.logo_img',
  103. 'alias'=>'yo'
  104. ];
  105. $log_list = HappinessStoreCommission::listPage($params);
  106. if($log_list===false)
  107. {
  108. return $this->error(HappinessStoreCommission::getStaticError());
  109. }
  110. // print_r($log_list);exit;
  111. if (empty($log_list['list'])) {
  112. if (false === $log_list['list']) {
  113. return $this->error(HappinessStoreCommission::getStaticError());
  114. }
  115. return $this->success('success', $log_list);
  116. }
  117. if (empty($stores)) {
  118. $store_ids = array_column($log_list['list'], 'store_id');
  119. $stores = HappinessStore::find()
  120. ->select('id,store_name,logo_img')
  121. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  122. ->andWhere(['like', 'store_name', $store_name])
  123. ->asArray()
  124. ->indexBy('id')
  125. ->all();
  126. }
  127. if (empty($users)) {
  128. $user_ids = array_column($log_list['list'], 'user_id');
  129. $users = User::find()
  130. ->select('id,nickname,mobile,avatar_url')
  131. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $user_ids])
  132. ->asArray()
  133. ->indexBy('id')
  134. ->all();
  135. }
  136. foreach ($log_list['list'] as &$list) {
  137. $store = $stores[$list['store_id']] ?? [];
  138. $user = $users[$list['user_id']] ?? [];
  139. $list['nickname'] = $user['nickname'] ?? '';
  140. $list['mobile'] = $user['mobile'] ?? '';
  141. $list['avatar_url'] = !empty($user['avatar_url']) ? $user['avatar_url'] : \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
  142. $list['store_name'] = $store['store_name'] ?? '';
  143. $list['store_logo'] = $store['logo_img'] ?? \Yii::$app->request->hostInfo . '/resources/img/common/o2o-store-default-logo.png';
  144. if ($list['status'] != StatusEnum::ENABLED) {
  145. $list['settle_status'] = 3;
  146. } else {
  147. if ($list['is_settlement'] == 0) {
  148. $list['settle_status'] = 1;
  149. } else {
  150. $list['settle_status'] = 2;
  151. }
  152. }
  153. }
  154. $total_order_amounts = HappinessStoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])->sum('order_money');
  155. $settle_order_amounts = HappinessStoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED,'is_settlement'=>1])->sum('amount_received');
  156. $not_settle_order_amounts = HappinessStoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED,'is_settlement'=>0])->sum('amount_received');
  157. if(empty($total_order_amounts)) $total_order_amounts = 0;
  158. if(empty($settle_order_amounts)) $settle_order_amounts = 0;
  159. if(empty($not_settle_order_amounts)) $not_settle_order_amounts = 0;
  160. $log_list['total_order_amounts'] = round($total_order_amounts, 2);
  161. $log_list['settle_order_amounts'] = round($settle_order_amounts, 2);
  162. $log_list['not_settle_order_amounts'] = round($not_settle_order_amounts, 2);
  163. $log_list['install_platform_store_clerk'] = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_PLATFORM_STORE_CLERK) ? 1 : 0;
  164. $log_list['install_secondary_card'] = MallAddons::isInstall($this->mall_id, 'SecondaryCard') ? 1 : 0;
  165. return $this->success('success', $log_list);
  166. }
  167. }