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); } }