request->isAjax) { if (\Yii::$app->request->isGet) { $params = \Yii::$app->request->get(); $where[] = ['mall_id' => $this->mall_id]; $where[] = ['pay_status' => 1]; $where[] = ['status' => StatusEnum::ENABLED]; if (!empty($params['keyword'])) { $user_list = User::lists(['where' => [['mall_id' => $this->mall_id], [ 'or', ['like', 'username', $params['keyword']], ['like', 'nickname', $params['keyword']], ]], 'select' => 'id']); $user_ids = array_column($user_list, 'id'); $where[] = ['in', 'user_id', $user_ids]; } if (!empty($params['start'])) $where[] = ['>=', 'pay_time', strtotime($params['start'])]; if (!empty($params['end'])) $where[] = ['<=', 'pay_time', strtotime($params['end'])]; if (!empty($params['min'])) $where[] = ['>=', 'pay_money', $params['min']]; if (!empty($params['max'])) $where[] = ['<=', 'pay_money', $params['max']]; $params['where'] = $where; $params['order'] = 'id desc'; $params['with'] = ['user', 'detail']; $params['limit'] = $params['limit'] ?? $this->pageSize; $page_data = StoreCashierOrder::listPage($params); if ($page_data === false) return $this->error(StoreWithdrawLog::getStaticError()); if (!empty($page_data['list'])) { $store_ids = array_column($page_data['list'], 'store_id'); $store_list = Store::lists([ 'where' => [ ['id' => $store_ids] ], 'index' => 'id' ]); foreach ($page_data['list'] as &$item) { $extra = json_decode($item['extra'], true); $item['extra'] = ''; $item['commission'] = 0; $item['store_name'] = $store_list[$item['store_id']]['store_name']??''; if ($extra) { $is_score_deduct = 0; $discount_money = 0; foreach ($extra as $k => $v) { if ($v) { switch ($k) { case "member_deduct_money": $item['extra'] .= '会员价优惠:' . $v; break; case "deduct_num_score": $is_score_deduct = 1; break; case "discount_money": $discount_money = $v; // $item['extra'] .= ' 优惠:' . $v; break; case "agent_commission": $item['commission'] += $v; // $item['extra'] .= ' 渠道分红:' . $v; break; case "distribution_commission": $item['commission'] += $v; // $item['extra'] .= ' 分销分红:' . $v; break; case "store_boss_commission": $item['commission']+=$v; break; case "area_commission": $item['commission'] += $v; break; } } } if ($is_score_deduct) { $item['extra'] .= ',积分抵扣优惠:' . $discount_money; } else { $item['extra'] .= ',优惠券优惠:' . $discount_money; } $item['extra'] = trim($item['extra'], ','); $item['commission'] = bcadd($item['commission'],0,2); } } } $page_data['export_list'] = StoreCashierOrder::fieldsList(true); return $this->success('ok', $page_data); } } if (\Yii::$app->request->post('flag') == 'EXPORT') { $params = \Yii::$app->request->post(); $params['mall_id'] = $this->mall_id; $filename = 'o2o门店收银台订单列表-' . date('YmdHis') . '_' . rand(10000, 99999); $model = StoreCashierOrder::find(); $model->where(['mall_id' => $params['mall_id']]); $model->andWhere(['pay_status' => 1]); if (!empty($params['start'])) $model->andWhere(['>=', 'pay_time', strtotime($params['start'])]); if (!empty($params['end'])) $model->andWhere(['<=', 'pay_time', strtotime($params['end'])]); if (!empty($params['min'])) $model->andWhere(['>=', 'pay_money', $params['min']]); if (!empty($params['max'])) $model->andWhere(['<=', 'pay_money', $params['max']]); if (!empty($params['keyword'])) { $user_list = User::lists(['where' => [['mall_id' => $params['mall_id']], [ 'or', ['like', 'username', $params['keyword']], ['like', 'nickname', $params['keyword']], ]], 'select' => 'id']); $user_ids = array_column($user_list, 'id'); $model->andWhere(['in', 'user_id', $user_ids]); } $model->with(['user']); $fields = $params['fields']; $fields = explode(',', $fields); $fields_arr = StoreCashierOrder::fieldsList(true); $have_select_field_arr = []; foreach ($fields as $value) { $have_select_field_arr[] = $fields_arr[$value]; } $csv = new CsvTool(); $csv->filename = $filename; $csv->export_mode = CsvTool::EXPORT_MODE_SYNC; $csv->header = $have_select_field_arr; $orders = $model->all(); empty($csv->header) && $csv->header = array_keys($orders[0]); $data = []; $store_ids = array_column($orders, 'store_id'); $store_list = Store::lists([ 'where' => [ ['id' => $store_ids] ], 'index' => 'id' ]); foreach ($orders as $order) { $row = []; foreach ($fields as $field) { if ($field == 'nickname') { $row[] = $order['user']['nickname']; } else if ($field == 'extra') { $extra = json_decode($order['extra'], true); $extra_content = ''; $is_score_deduct = 0; $discount_money = 0; if ($extra) { foreach ($extra as $k => $v) { if ($v) { switch ($k) { case "member_deduct_money": $extra_content .= ',会员价优惠:' . $v; break; case "deduct_num_score": $is_score_deduct = 1; break; case "discount_money": $discount_money = $v; // $extra_content .= ' 优惠:' . $v; break; case "agent_commission": $extra_content .= ',渠道分红:' . $v; break; case "distribution_commission": $extra_content .= ',分销分红:' . $v; break; } } } if ($is_score_deduct) { $extra_content .= ',积分抵扣优惠:' . $discount_money; } else { $extra_content .= ',优惠券优惠:' . $discount_money; } } $row[] = trim($extra_content, ','); } else if ($field == 'pay_time') { $row[] = !empty($order['pay_time']) ? date('Y-m-d H:i:s', $order['pay_time']) : ''; } else if($field=='store_name'){ $row[] = $store_list[$order['store_id']]['store_name']?? ''; }else { if ((isset($order[$field]))) $row[] = $order[$field]; } } $data[] = $row; } $csv->data = $data; $csv->export(); } return $this->render($this->action->id); } public function actionCommissionAndScoreList() { $params = \Yii::$app->request->get(); $wallet_type = 'commission'; if (!empty($params['wallet_type'])) $wallet_type = $params['wallet_type']; $condition = [ 'where' => [ ['source_table' => ['store_cashier_order',StoreCashierOrder::tableName(),'store_cashier_order_detail']], ['source_table_id' => $params['order_id']] ], ]; CapitalLog::$capitalType = "{$wallet_type}"; $list = CapitalLog::getList($condition, 0); $level = UserLevel::find()->select("name,level")->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])->asArray()->all(); $level_data = array_column($level, 'name', 'level'); CapitalLog::$capitalType = "{$wallet_type}_frozen"; $condition['where'][] = ['status' => 0]; $frozen_list = CapitalLog::getList($condition, 1); $list = array_merge($list, $frozen_list); return $this->success('操作成功', ['list' => $list, 'user_level' => $level_data]); } public function actionGetCouponList() { $params = \Yii::$app->request->get(); $type = $params['type'] ?? 2; $store_id = $this->store_id; $is_install = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_COUPON); $coupon_list = []; if ($is_install) { $coupon_list = AddonsCoupon::lists([ 'where' => [ ['store_id' => $store_id], ['type' => $type], ['status' => StatusEnum::ENABLED], ['coupon_status' => AddonsCouponEnum::STATUS_RECEIVING], ], 'select' => 'id,name' ]); } return $this->success('ok', ['coupon_list' => $coupon_list]); } public function actionShowMiniPromotionCode() { $request = \Yii::$app->request; if ($request->isAjax) { if ($request->isPost) { $params = \Yii::$app->request->post(); // 检查提交的参数 $res = \Yii::$app->services->validate->validate($params, [ [['type'], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $store = Store::findOne(['mall_id' => $this->mall_id, 'id' => $this->store_id]); if (empty($store)) return $this->error('店铺不存在'); $model = StoreMiniCode::findOne(['store_id' => $store['id'], 'mall_id' => $this->mall_id, 'type' => $params['type']]); if (empty($model)) { $mall = $this->mall; $content = [ 'mall_id' => $this->mall_id, 'store_id' => $store['id'], 'mall_sign' => $mall['mall_sign'], 'type' => $params['type'], ]; $content = json_encode($content); if ($params['type'] == 1) { $page = 'plugins2/Store/store/index'; } else { $page = '/plugins2/Store/pay/cashRegister'; } $code = md5($content); $obj = new MiniQrCode(); $applet_code = $obj->getAppletQrCode($this->mall_id, $page, $code); $params['mall_id'] = $this->mall_id; $params['code'] = $code; $params['store_id'] = $store['id']; $params['content'] = $content; $params['applet_code'] = $applet_code; $model = StoreMiniCode::setData($params); } $applet_url = $model['applet_code']; $this->success('获取成功', ['applet_url' => $applet_url]); } } } }