| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- namespace addons\Happiness\agent\controllers;
- use addons\Happiness\common\models\HappinessStore;
- use addons\Happiness\common\models\HappinessStoreCommission;
- use addons\Store\common\models\StoreCommission;
- use common\enums\AddonsEnum;
- use common\enums\DownloadEnum;
- use common\enums\StatusEnum;
- use common\helpers\csv\CsvExportHelper;
- use common\models\mall\MallAddons;
- use common\models\user\User;
- class StoreAssetsController extends BaseController
- {
- public function actionIndex()
- {
- if (!\Yii::$app->request->isAjax) {
- return $this->render('/store-assets/index');
- }
- if (\Yii::$app->request->isGet) {
- $type = 1;
- return $this->orderDetailList($type);
- }
- if (\Yii::$app->request->post('flag') == 'EXPORT') {
- $post = \Yii::$app->request->post();
- $post['mall_id'] = $this->mall_id;
- $filename = '平台-门店收银台资产明细列表-' . date('YmdHis') . '_' . rand(10000, 99999);
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_STORE_CASHIER, StoreCommission::class, 'exportHandle', $post);
- if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- }
- private function orderDetailList($type = 1)
- {
- $page = \Yii::$app->request->get('page', 1);
- $limit = \Yii::$app->request->get('limit', $this->pageSize);
- $store_name = \Yii::$app->request->get('store_name');
- $user_id = \Yii::$app->request->get('user_id');
- $nickname = \Yii::$app->request->get('nickname');
- $mobile = \Yii::$app->request->get('mobile');
- $order_no = \Yii::$app->request->get('order_no');
- $order_status = \Yii::$app->request->get('order_status');
- if (!in_array($order_status, [0, 1, 2, 3])) {
- return $this->error('参数错误:order_status');
- }
- $wheres[] = ['yo.mall_id' => $this->mall_id, 'yo.status' => StatusEnum::ENABLED, 'yo.is_settlement' => [0,1]];
- //or条件
- $wheres[] = ['or', ['in', 'o.city_id', $this->city_ids], ['in', 'o.district_id', $this->district_ids], ['in',
- 'o.province_id', $this->province_ids]];
- $stores = [];
- if (!empty($store_name)) {
- $stores = HappinessStore::find()
- ->select('id,store_name,logo_img')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->andWhere(['like', 'store_name', $store_name])
- ->asArray()
- ->indexBy('id')
- ->all();
- $store_ids = array_column($stores, 'id');
- $wheres[] = ['yo.store_id' => $store_ids];
- }
- if (!empty($user_id)) {
- $wheres[] = ['yo.user_id' => $user_id];
- }
- $user_wheres = [];
- $users = [];
- if (!empty($nickname)) {
- $user_wheres[] = ['like', 'nickname', $nickname];
- }
- if (!empty($mobile)) {
- $user_wheres[] = ['like', 'mobile', $mobile];
- }
- if (!empty($user_wheres)) {
- $user_wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED];
- $query = User::find()->select('id,nickname,mobile,avatar_url');
- foreach ($user_wheres as $where) {
- $query->andWhere($where);
- }
- $users = $query->asArray()->indexBy('id')->all();
- $user_ids = array_column($users, 'id');
- $wheres[] = ['yo.user_id' => $user_ids];
- }
- if (!empty($order_no)) {
- $wheres[] = ['like', 'yo.order_no', $order_no];
- }
- if (!empty($order_status)) {
- if (1 == $order_status) {
- $wheres[] = ['yo.is_settlement' => 0];
- } elseif (2 == $order_status) {
- $wheres[] = ['yo.is_settlement' => 1];
- } else {
- $wheres[] = ['!=', 'status', StatusEnum::ENABLED];
- }
- }
- $join = [['LEFT JOIN', HappinessStore::tableName(). ' as o', "o.id = yo.store_id"]];
- $params = [
- // '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',
- 'where' => $wheres,
- 'order' => 'yo.created_at desc',
- 'page' => $page,
- 'limit' => $limit,
- 'join'=>$join,
- 'select'=>'yo.*,o.city_id,o.province_id,o.district_id,o.store_name,o.logo_img',
- 'alias'=>'yo'
- ];
- $log_list = HappinessStoreCommission::listPage($params);
- if($log_list===false)
- {
- return $this->error(HappinessStoreCommission::getStaticError());
- }
- // print_r($log_list);exit;
- if (empty($log_list['list'])) {
- if (false === $log_list['list']) {
- return $this->error(HappinessStoreCommission::getStaticError());
- }
- return $this->success('success', $log_list);
- }
- if (empty($stores)) {
- $store_ids = array_column($log_list['list'], 'store_id');
- $stores = HappinessStore::find()
- ->select('id,store_name,logo_img')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->andWhere(['like', 'store_name', $store_name])
- ->asArray()
- ->indexBy('id')
- ->all();
- }
- if (empty($users)) {
- $user_ids = array_column($log_list['list'], 'user_id');
- $users = User::find()
- ->select('id,nickname,mobile,avatar_url')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $user_ids])
- ->asArray()
- ->indexBy('id')
- ->all();
- }
- foreach ($log_list['list'] as &$list) {
- $store = $stores[$list['store_id']] ?? [];
- $user = $users[$list['user_id']] ?? [];
- $list['nickname'] = $user['nickname'] ?? '';
- $list['mobile'] = $user['mobile'] ?? '';
- $list['avatar_url'] = !empty($user['avatar_url']) ? $user['avatar_url'] : \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
- $list['store_name'] = $store['store_name'] ?? '';
- $list['store_logo'] = $store['logo_img'] ?? \Yii::$app->request->hostInfo . '/resources/img/common/o2o-store-default-logo.png';
- if ($list['status'] != StatusEnum::ENABLED) {
- $list['settle_status'] = 3;
- } else {
- if ($list['is_settlement'] == 0) {
- $list['settle_status'] = 1;
- } else {
- $list['settle_status'] = 2;
- }
- }
- }
- $total_order_amounts = HappinessStoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])->sum('order_money');
- $settle_order_amounts = HappinessStoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED,'is_settlement'=>1])->sum('amount_received');
- $not_settle_order_amounts = HappinessStoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED,'is_settlement'=>0])->sum('amount_received');
- if(empty($total_order_amounts)) $total_order_amounts = 0;
- if(empty($settle_order_amounts)) $settle_order_amounts = 0;
- if(empty($not_settle_order_amounts)) $not_settle_order_amounts = 0;
- $log_list['total_order_amounts'] = round($total_order_amounts, 2);
- $log_list['settle_order_amounts'] = round($settle_order_amounts, 2);
- $log_list['not_settle_order_amounts'] = round($not_settle_order_amounts, 2);
- $log_list['install_platform_store_clerk'] = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_PLATFORM_STORE_CLERK) ? 1 : 0;
- $log_list['install_secondary_card'] = MallAddons::isInstall($this->mall_id, 'SecondaryCard') ? 1 : 0;
- return $this->success('success', $log_list);
- }
- }
|