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','platform-store-clerk','secondary_card'])) { return $this->error('参数错误: tabname'); } if ('order-detail' == $tabname || 'platform-store-clerk' == $tabname) { $type = $tabname == 'order-detail' ? 1 : 3; return $this->orderDetailList($type); } else if('cashier' == $tabname) { return $this->cashierList(); } else if('secondary_card' == $tabname) { return $this->secondaryCardList(); } } if (\Yii::$app->request->post('flag') == 'EXPORT') { $post = \Yii::$app->request->post(); $post['mall_id'] = $this->mall_id; $filename = '平台-门店收银台资产明细列表-' . date('YmdHis') . '_' . rand(10000, 99999); $method = 'exportHandle'; $type = DownloadEnum::TYPE_STORE_CASHIER; if ($post['activityTab'] == 'order-detail') { $filename = '平台-门店订单明细列表-' . date('YmdHis') . '_' . rand(10000, 99999); $method = 'orderDetailExportHandle'; $type = DownloadEnum::TYPE_ASSETS; } $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, $type, StoreCommission::class, $method, $post); if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError()); return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!'); } } /** * @name: * @msg: 门店订单明细 * @param {*} * @return {*} */ 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[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => $type]; $stores = []; if (!empty($store_name)) { $stores = Store::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[] = ['store_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,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' => 'created_at desc', 'page' => $page, 'limit' => $limit ]; $log_list = StoreCommission::listPage($params); $log_list['orderDetailFieldsList'] = StoreCommission::orderDetailFieldsList(); if (empty($log_list['list'])) { if (false === $log_list['list']) { return $this->error(StoreCommission::getStaticError()); } return $this->success('success', $log_list); } if (empty($stores)) { $store_ids = array_column($log_list['list'], 'store_id'); $stores = Store::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 = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => $type])->sum('order_money'); $settle_order_amounts = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED,'is_settlement'=>1, 'type' => $type])->sum('amount_received'); $not_settle_order_amounts = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED,'is_settlement'=>0, 'type' => $type])->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); } // 收银台收入明细 private function cashierList() { $page = \Yii::$app->request->get('page', 1); $limit = \Yii::$app->request->get('limit', $this->pageSize); $min_amount = \Yii::$app->request->get('min_amount'); $max_amount = \Yii::$app->request->get('max_amount'); $start_time = \Yii::$app->request->get('start_time'); $end_time = \Yii::$app->request->get('end_time'); $store_name = \Yii::$app->request->get('store_name'); $user_id = \Yii::$app->request->get('user_id'); $nickname = \Yii::$app->request->get('nickname'); $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => 2]; if (!empty($min_amount)) { $wheres[] = ['>=', 'pay_money', $min_amount]; } if (!empty($max_amount)) { $wheres[] = ['<=', 'pay_money', $max_amount]; } if (!empty($start_time)) { $wheres[] = ['>=', 'created_at', $start_time]; } if (!empty($end_time)) { $wheres[] = ['<=', 'created_at', $end_time]; } if (!empty($store_name)) { $stores = Store::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[] = ['store_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]; } $params = [ 'select' => 'id,mall_id,store_id,user_id,order_no,order_money,pay_money,discount_money,amount_received,is_settlement,service_charge,created_at', 'where' => $wheres, 'order' => 'created_at desc', 'page' => $page, 'limit' => $limit, ]; // dd($params); $commission_logs = StoreCommission::listPage($params); if (false === $commission_logs['list']) { return $this->error(StoreCommission::getStaticError()); } if (!empty($commission_logs['list'])) { if (empty($users)) { $user_ids = array_column($commission_logs['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(); } if (empty($stores)) { $store_ids = array_column($commission_logs['list'], 'store_id'); $stores = Store::find() ->select('id,store_name,logo_img') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $store_ids]) ->andWhere(['like', 'store_name', $store_name]) ->asArray() ->indexBy('id') ->all(); } foreach ($commission_logs['list'] as &$log) { $user = $users[$log['user_id']] ?? []; $store = $stores[$log['store_id']] ?? []; $log['nickname'] = $user['nickname'] ?? ''; $log['nickname'] = $user['nickname'] ?? ''; $log['avatar_url'] = !empty($user['avatar_url']) ? $user['avatar_url'] : \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png'; $log['mobile'] = $user['mobile'] ?? ''; $log['store_name'] = $store['store_name'] ?? ''; $log['logo_img'] = $store['logo_img'] ?? ''; } } $total_real_pay_amounts = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => 2])->sum('order_money'); $total_order_numbers = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => 2])->count(); $total_receive_amounts = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => 2])->sum('amount_received'); if(empty($total_real_pay_amounts)) $total_real_pay_amounts = 0; if(empty($total_receive_amounts)) $total_receive_amounts = 0; if(empty($total_order_numbers)) $total_order_numbers = 0; $commission_logs['total_real_pay_amounts'] = round($total_real_pay_amounts, 2); $commission_logs['total_receive_amounts'] = round($total_receive_amounts, 2); $commission_logs['total_order_numbers'] = $total_order_numbers; // 导出字段列表 $export_fields = StoreCommission::fieldsList(); $commission_logs['export_list'] = $export_fields; $commission_logs['install_platform_store_clerk'] = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_PLATFORM_STORE_CLERK) ? 1 : 0; return $this->success('success', $commission_logs); } private function secondaryCardList() { $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'); } $type = 4; $wheres[] = ['mall_id' => $this->mall_id, ]; $wheres[] = ['status' => StatusEnum::ENABLED]; $wheres[] = [ 'type' => $type]; $stores = []; if (!empty($store_name)) { $stores = Store::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[] = ['store_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,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', 'where' => $wheres, 'order' => 'created_at desc', 'page' => $page, 'limit' => $limit ]; $log_list = StoreCommission::listPage($params); if (empty($log_list['list'])) { if (false === $log_list['list']) { return $this->error(StoreCommission::getStaticError()); } return $this->success('success', $log_list); } if (empty($stores)) { $store_ids = array_column($log_list['list'], 'store_id'); $stores = Store::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'; } $total_order_amounts = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'type' => $type])->sum('order_money'); $settle_order_amounts = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED,'is_settlement'=>1, 'type' => $type])->sum('amount_received'); $not_settle_order_amounts = StoreCommission::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED,'is_settlement'=>0, 'type' => $type])->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_secondary_card'] = MallAddons::isInstall($this->mall_id, 'SecondaryCard') ? 1 : 0; return $this->success('success', $log_list); } /** * @name: * @msg: 获取插件分佣金额 * @return {*} */ public function actionAddonsCommission() { if (!\Yii::$app->request->isGet) { return $this->error('请求方式错误'); } $id = \Yii::$app->request->get('id'); $user_id = \Yii::$app->request->get('user_id'); $order_no = \Yii::$app->request->get('order_no'); $is_settlement = \Yii::$app->request->get('is_settlement'); if ( empty($id) || empty($user_id) || empty($order_no) || !isset($is_settlement) ) { return $this->error('参数错误'); } $addons_name_map = AddonsEnum::getAddonsNameMap(); $result = [ 'Agent' => ['name' => $addons_name_map['Agent'], 'value' => 0], 'Area' => ['name' => $addons_name_map['Area'], 'value' => 0], // 'Boss' => ['name' => $addons_name_map['Boss'], 'value' => 0], 'Distribution' => ['name' => $addons_name_map['Distribution'], 'value' => 0], 'Rebate' => ['name' => $addons_name_map['Rebate'], 'value' => 0], ]; $log = StoreCommission::find() ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $id, 'user_id' => $user_id, 'order_no' => $order_no, 'is_settlement' => $is_settlement]) ->one(); if (empty($log)) { return $this->success('success111', $result); } $order = StoreOrder::findOne(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'user_id' => $user_id, 'order_no' => $order_no]); $order_detail = $order->detail; $order_detail_ids = array_column(ArrayHelper::toArray($order_detail), 'id'); CapitalLog::$capitalType = 'commission_frozen'; $commission_frozen_logs = CapitalLog::find() ->where(['mall_id' => $this->mall_id, 'source_table' => 'store_order_detail', 'source_table_id' => $order_detail_ids]) ->asArray() ->all(); if (!empty($commission_frozen_logs)) { foreach ($commission_frozen_logs as $flog) { if ($flog['status'] != 0) { continue; } if (!isset($result[$flog['from_type']]['value'])) { $result[$flog['from_type']]['value'] = 0; } $result[$flog['from_type']]['name'] = $addons_name_map[$flog['from_type']]; $result[$flog['from_type']]['value'] += $flog['change_num'] ?? 0; } } CapitalLog::$capitalType = 'commission'; $commission_logs = CapitalLog::find() ->where(['mall_id' => $this->mall_id, 'source_table' => 'store_order_detail', 'source_table_id' => $order_detail_ids]) ->asArray() ->all(); if (!empty($commission_logs)) { foreach ($commission_logs as $log) { if (!isset($result[$log['from_type']]['value'])) { $result[$log['from_type']]['value'] = 0; } $result[$log['from_type']]['name'] = $addons_name_map[$log['from_type']]; $result[$log['from_type']]['value'] += $log['change_num'] ?? 0; } } foreach ($result as &$rst) { $rst['value'] = round($rst['value'], 2); } //加上股东 $store_order_commission = OrderCommissionLogic::getOrderAddonsCommission($order->id); if($store_order_commission && isset($store_order_commission['Boss'])){ $result['Boss'] = ['name' => $addons_name_map['Boss'], 'value' => 0]; foreach($store_order_commission['Boss'] as $info){ $result['Boss']['value'] = bcadd($result['Boss']['value'],$info['commission'],2); } } if($store_order_commission && isset($store_order_commission['Rebate'])){ $result['Rebate'] = ['name' => $addons_name_map['Rebate'], 'value' => 0]; foreach($store_order_commission['Rebate'] as $info){ $result['Rebate']['value'] = bcadd($result['Rebate']['value'],$info['commission'],2); } } return $this->success('success222', $result); } }