request->isAjax) { return $this->render('/store-assets/index'); } if (\Yii::$app->request->isGet) { $tabname = \Yii::$app->request->get('tabname'); if (empty($tabname) || !in_array($tabname, ['order-detail', 'cashier'])) { return $this->error('参数错误: tabname'); } if ('order-detail' == $tabname) { return $this->orderDetailList(); } } 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_ASSETS, MchCommission::class, 'orderDetailExportHandle', $post); if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError()); return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!'); } } public function actionTotal() { $total_order_amounts = MchCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => 1])->sum('order_money'); $settle_order_amounts = MchCommission::find()->where(['mall_id' => $this->mall_id, 'is_settlement'=>1,'status' => StatusEnum::ENABLED, 'type' => 1])->sum('order_money'); $not_settle_order_amounts = MchCommission::find()->where(['mall_id' => $this->mall_id, 'is_settlement'=>0,'status' => StatusEnum::ENABLED, 'type' => 1])->sum('order_money'); $log_list['total_order_amounts'] = !empty($total_order_amounts)?bcadd($total_order_amounts,0,2):0; $log_list['settle_order_amounts'] = !empty($settle_order_amounts)?bcadd($settle_order_amounts,0,2):0; $log_list['not_settle_order_amounts'] = !empty($not_settle_order_amounts)?bcadd($not_settle_order_amounts,0,2):0; return $this->success('',$log_list); } /** * @name: * @msg: 门店订单明细 * @param {*} * @return {*} */ private function orderDetailList() { $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[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => 1]; $stores = []; if (!empty($store_name)) { $stores = Mch::find() ->select('id,store_name,logo_img') ->where(['mall_id' => $this->mall_id, 'status' =>[StatusEnum::ENABLED,StatusEnum::DISABLED]]) ->andWhere(['like', 'store_name', $store_name]) ->asArray() ->indexBy('id') ->all(); $store_ids = array_column($stores, 'id'); $wheres[] = ['mch_id' => $store_ids]; } if (!empty($user_id)) { $wheres[] = ['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[] = ['user_id' => $user_ids]; } if (!empty($order_no)) { $wheres[] = ['like', 'order_no', $order_no]; } if (!empty($order_status)) { if (1 == $order_status) { $wheres[] = ['is_settlement' => 0]; } elseif (2 == $order_status) { $wheres[] = ['is_settlement' => 1]; } else { $wheres[] = ['!=', 'status', StatusEnum::ENABLED]; } } $params = [ 'select' => 'id,mall_id,mch_id,user_id,order_no,order_money,pay_money,discount_money,addons_bonus,service_charge,amount_received,is_settlement,created_at,status', 'where' => $wheres, 'order' => 'created_at desc', 'page' => $page, 'limit' => $limit ]; $log_list = MchCommission::listPage($params); $log_list['orderDetailFieldsList'] = MchCommission::orderDetailFieldsList(); if (empty($log_list['list'])) { if (false === $log_list['list']) { return $this->error(MchCommission::getStaticError()); } return $this->success('success', $log_list); } if (empty($stores)) { $stores = Mch::find() ->select('id,store_name,logo_img') ->where(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED]]) ->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['mch_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 = $settle_order_amounts = $not_settle_order_amounts = 0; // $page = 1; // $limit = 200; // do { // $offset = ($page - 1) * $limit; // $page++; // $commissions = MchCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => 1])->limit($limit)->offset($offset)->all(); // if (!empty($commissions)) { // foreach ($commissions as $data) { // $total_order_amounts += $data->order_money; // if (1 == $data->is_settlement) { // $settle_order_amounts += $data->order_money; // } else { // $not_settle_order_amounts += $data->order_money; // } // } // } // } while ($commissions); // $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); return $this->success('success', $log_list); } }