request->isAjax) { return $this->render('/store/index'); } if (\Yii::$app->request->isGet) { $page = \Yii::$app->request->get('page', 1); $limit = \Yii::$app->request->get('limit', $this->pageSize); $store_name = \Yii::$app->request->get('store_name'); $storeowner = \Yii::$app->request->get('storeowner'); $nickname = \Yii::$app->request->get('nickname'); // 门店状态,1:正常;2:过期;3:禁用 $status = \Yii::$app->request->get('status'); $time = time(); $wheres[] = ['mall_id' => $this->mall_id]; $wheres[] = ['check_status' => StatusEnum::ENABLED]; if (empty($status)) { $wheres[] = ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]; } else { if (1 == $status) { $wheres[] = ['status' => StatusEnum::ENABLED]; $wheres[] = ['or', ['>=', 'expire_time', $time], ['expire_time' => 0]]; } elseif (2 == $status) { $wheres[] = ['status' => StatusEnum::ENABLED]; $wheres[] = ['<=', 'expire_time', $time]; $wheres[] = ['!=', 'expire_time', 0]; } elseif (3 == $status) { $wheres[] = ['status' => StatusEnum::DISABLED]; } else { return $this->error('参数错误'); } } if (!empty($store_name)) { $store_name = trim($store_name); $wheres[] = ['or', ['like', 'store_name', $store_name], ['id' => $store_name]]; } if (!empty($storeowner)) { $wheres[] = ['like', 'shop_owner', $storeowner]; } if (!empty($nickname)) { $users = User::find() ->select('id,nickname,mobile,avatar_url') ->where(['like', 'nickname', $nickname]) ->andWhere(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->indexBy('id') ->all(); $user_ids = array_column($users, 'id'); $wheres[] = ['user_id' => $user_ids]; } $params = [ 'select' => 'id,mall_id,user_id,shop_owner,business_id,shop_mobile,store_name,province_id,city_id,district_id,address,logo_img,total_money,balance,expire_time,user_nums,status,created_at,is_freeze,total_order_money,total_settled_amount,unsettled_amount,total_num', 'where' => $wheres, 'order' => 'created_at desc', 'page' => $page, 'limit' => $limit, 'with' => ['business' => function ($query) { $query->select('id,nickname,mobile'); }], ]; $store_list = HappinessStore::listPage($params); if (false === $store_list) { return $this->error(HappinessStore::getStaticError()); } if (!empty($store_list['list'])) { if (empty($users)) { $user_ids = array_unique(array_column($store_list['list'], 'user_id')); $users = User::find() ->select('id,nickname,mobile,avatar_url') ->where(['id' => $user_ids, 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->indexBy('id') ->all(); } $region_ids = []; $province_ids = array_unique(array_column($store_list['list'], 'province_id')); $city_ids = array_unique(array_column($store_list['list'], 'city_id')); $district_ids = array_unique(array_column($store_list['list'], 'district_id')); $street_ids = array_unique(array_column($store_list['list'], 'street_id')); $community_ids = array_unique(array_column($store_list['list'], 'community_id')); $region_ids = array_merge($province_ids, $city_ids, $district_ids); $regions = Region::find() ->select('id,name') ->where(['id' => $region_ids]) ->asArray() ->indexBy('id') ->all(); $streets = town::find() ->select('id,name') ->where(['id' => $street_ids]) ->asArray() ->indexBy('id') ->all(); $communitys = StoreCommunity::find() ->select('id,community_name') ->where(['mall_id' => $this->mall_id, 'id' => $community_ids]) ->asArray() ->indexBy('id') ->all(); $H5Url = MallHost::getHost($this->mall_id, 'h5_url'); foreach ($store_list['list'] as &$list) { $h5_domain = $H5Url . '/#/plugins2/Store/pay/cashRegister?sign=' . $this->mall['mall_sign']; $user = $users[$list['user_id']] ?? []; $category = $categorys[$list['c_id']] ?? []; $province = $regions[$list['province_id']] ?? []; $city = $regions[$list['city_id']] ?? []; $district = $regions[$list['district_id']] ?? []; $streetInfo = $streets[$list['street_id']] ?? []; if ($list['community_id'] == '-1') { $CommunityInfo = '其它社区'; } else { if (isset($communitys[$list['community_id']])) { $CommunityInfo = $communitys[$list['community_id']]['community_name']; } else { $CommunityInfo = ''; } } $list['nickname'] = $user['nickname'] ?? ''; $list['user_mobile'] = $user['mobile'] ?? ''; $list['avatar_url'] = $user['avatar_url'] ?: \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png'; $list['business']['avatar_url'] = $list['business']['avatar_url'] ?: \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png'; //判断address字段是否只是详细 preg_match('/(.*?(?:省|自治区|北京市|天津市|上海市|重庆市))+(.*?(?:市|自治州|地区|区划|县))+(.*?(?:市|区|县|镇|乡|街道))/', $list['address'], $matches); if (count($matches) > 1) { $list['store_address'] = $list['address']; } else { $list['store_address'] = ($province['name'] ?? '') . ($city['name'] ?? '') . ($district['name'] ?? '') . ($streetInfo['name'] ?? '') . ($CommunityInfo ?? '') . $list['address']; } // 门店状态,1:正常;2:过期;3:禁用 if ($list['status'] == StatusEnum::ENABLED) { $list['store_status'] = 1; } elseif ($list['status'] == StatusEnum::DISABLED) { $list['store_status'] = 3; } else { $list['store_status'] = 1; } $h5_domain .= '&store_id=' . $list['id']; $list['store_collection_url'] = $h5_domain; $list['promotion_code'] = $H5Url . '/#/plugins2/Store/store/index?store_id=' . $list['id'] . "&sign=" . $this->mall['mall_sign']; } } $store_list['store_login_url'] = \Yii::$app->request->hostInfo . '?r=happiness/client/auth/login&sign=' . $this->mall['mall_sign']; $cate_list = StoreCate::find() ->select('id,name') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->all(); $store_list['cate_list'] = $cate_list; $recharge_list = \Yii::$app->services->setting->addons->get($this->mall_id, HappinessEnum::ADDONS_NAME, 'basic.recharge_list'); $recharge_list = isset($recharge_list) ? json_decode($recharge_list, true) : []; $store_list['recharge_list'] = $recharge_list; return $this->success('success', $store_list); } } /** * @name: * @msg: 切换门店状态 * @param {*} * @return {*} */ public function actionSwitchStatus() { if (!\Yii::$app->request->isPost) { return $this->error('请求方式错误'); } $post = \Yii::$app->request->post(); $rules = [ [['store_id', 'status'], 'required'], [['store_id', 'status'], 'integer'], ['status', 'in', 'range' => [1, 3]], ]; $res = \Yii::$app->services->validate->validate($post, $rules); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); if (1 == $post['status']) { $status = StatusEnum::ENABLED; } else { $status = StatusEnum::DISABLED; } $params = [ 'id' => $post['store_id'], 'status' => $status, 'mall_id' => $this->mall_id, ]; $res = HappinessStore::setData($params); if (false === $res) { return $this->error(HappinessStore::getStaticError()); } return $this->success('操作成功'); } /** * @name: * @msg: 根据地区id获取第一层子级地区信息列表 * @param {*} * @return {*} */ public function actionGetRegions() { if (!\Yii::$app->request->isGet) { return $this->error('请求方式错误'); } $region_id = \Yii::$app->request->get('region_id'); $level = \Yii::$app->request->get('level'); if (empty($region_id)) { return $this->error('参数错误'); } $region = Region::findOne($region_id); if (empty($region) && $level <= 3) { return $this->error('地区信息未找到'); } if (isset($level) && $level >= 3) { if ($level == 3) { $region_list = Town::find() ->select('id,name') ->where(['district_id' => $region->id]) ->asArray() ->indexBy('id') ->all(); } else { $region_list = StoreCommunity::find() ->select('id,community_name') ->where(['street_id' => $region_id, 'mall_id' => $this->mall_id, 'status' => 0]) ->asArray() ->indexBy('id') ->all(); $data = ['id' => '-1', 'community_name' => '其它社区']; $region_list[] = $data; } } else { $region_list = Region::find() ->select('id,name,lng,lat') ->where(['parent_id' => $region->id]) ->asArray() ->indexBy('id') ->all(); } return $this->success('success', $region_list); } /** * @name: * @msg: 获取用户列表 * @param {*} * @return {*} */ public function actionGetUsers() { if (!\Yii::$app->request->isGet) { return $this->error('请求方式错误'); } $user_id = \Yii::$app->request->get('user_id'); $keyword = \Yii::$app->request->get('keyword'); $page = \Yii::$app->request->get('page', 1); $limit = \Yii::$app->request->get('limit', $this->pageSize); $store_user_ids = HappinessStore::find()->select('user_id')->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])->asArray()->column(); $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]; $wheres[] = ['not in', 'id', $store_user_ids]; if (!empty($user_id)) { $wheres[] = ['id' => $user_id]; } if (!empty($keyword)) { $wheres[] = ['or', ['like', 'nickname', $keyword], ['like', 'mobile', $keyword]]; } $params = [ 'select' => 'id,nickname,avatar_url,mobile,level,parent_id', 'where' => $wheres, 'order' => 'created_at desc', 'page' => $page, 'limit' => $limit, ]; $user_list = User::listPage($params); if (empty($user_list['list'])) { if (false === $user_list['list']) { return $this->error(User::getStaticError()); } } else { $levels = UserLevel::find() ->select('id,level,name') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->indexBy('level') ->all(); $parent_ids = array_column($user_list['list'], 'parent_id'); $parent_users = User::find() ->select('id,nickname,avatar_url,mobile,level,parent_id') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $parent_ids]) ->asArray() ->indexBy('id') ->all(); foreach ($user_list['list'] as &$user) { if (empty($user['avatar_url'])) { $user['avatar_url'] = \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png'; } $level = $levels[$user['level']] ?? []; $parent_user = $parent_users[$user['parent_id']] ?? []; $user['level_name'] = $level['name'] ?? ''; $user['parent_nickname'] = $parent_user['nickname'] ?? ''; } } return $this->success('success', $user_list); } /** * @name: * @msg: 门店添加/编辑 * @param {*} * @return {*} */ public function actionStorage() { if (!\Yii::$app->request->isAjax) { return $this->render('/store/add-edit'); } if (\Yii::$app->request->isGet) { $regions = Region::find() ->select('id,name,lng,lat') ->where(['level' => 1]) ->asArray() ->indexBy('id') ->all(); $setting = \Yii::$app->services->setting->addons->get($this->mall_id, HappinessEnum::ADDONS_NAME, 'basic'); $configs = [ 'delivery_amount' => $setting['delivery_amount'], //起送金额 'delivery_fee' => $setting['delivery_fee'], //配送费设置 'start_limit' => $setting['start_limit'], //初始公里数 'start_amount' => $setting['start_amount'], //初始配送费 'add_limit' => $setting['add_limit'], //每次增加配送费公里数 'add_amount' => $setting['add_amount'], //每次增加配送费数量 ]; if ($setting['is_location_limit'] == 1) { $configs['localtion_limit'] = $setting['localtion_limit']; } else { $configs['localtion_limit'] = ''; } return $this->success('success', ['provinces' => $regions, 'configs' => $configs]); } else { $post = \Yii::$app->request->post(); $rules = [ [['user_id', 'shop_mobile', 'shop_owner', 'store_name', 'logo_img', 'license_img', 'province_id', 'city_id', 'district_id', 'address', 'longitude', 'latitude'], 'required'], [['user_id', 'shop_mobile', 'province_id', 'city_id', 'district_id','street_id', 'merchant_distribution', 'self_mention', 'shop_status','business_id'], 'integer'], [['longitude', 'latitude'], 'number'], [['shop_owner', 'store_name', 'store_desc', 'logo_img', 'license_img', 'address', 'business_time_start', 'business_time_end'], 'string', 'max' => 255], [['logo_img', 'license_img'], 'url'], ['shop_mobile', function ($attribute, $params) { if (!RegularHelper::verify('mobile', $this->$attribute)) { $this->addError($attribute, '手机号格式错误'); } }], [['freight_type', 'intra_city_distribution'], 'safe'] ]; $res = \Yii::$app->services->validate->validate($post, $rules); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $post['mall_id'] = $this->mall_id; // $post['expire_time'] = strtotime("+1 year"); if (empty($post['store_desc'])) $post['store_desc'] = ''; $setting = \Yii::$app->services->setting->addons->get($this->mall_id, HappinessEnum::ADDONS_NAME, 'basic'); $post['is_alone'] = $post['intra_city_distribution']['is_alone']; if ($post['is_alone'] == 1) { $post['distribution_scope'] = $post['intra_city_distribution']['distribution_scope']; } else if ($post['is_alone'] == 0) { $post['distribution_scope'] = $setting['localtion_limit'] ? $setting['localtion_limit'] : 100000; if ($setting['is_location_limit'] == 0) $post['distribution_scope'] = 100000; } $post['check_status']=HappinessEnum::CHECK_ADOPT; $streets = Town::find() ->where(['district_id'=>$post['district_id']]) ->select('id,name') ->asArray() ->indexBy('id') ->all(); $street_name = $streets[$post['street_id']]['name']??''; $region_ids = [$post['province_id'], $post['city_id'], $post['district_id']]; $regions = Region::find() ->select('id,name') ->where(['id' => $region_ids]) ->asArray() ->indexBy('id') ->all(); $name_rule=!empty($setting['name_rule'])?json_decode($setting['name_rule'],true):[]; $store_name=''; if(!empty($name_rule)) { if(in_array('province',$name_rule)) { $store_name.=$regions[$post['province_id']]['name'].'-'; } if(in_array('city',$name_rule)) { $store_name.=$regions[$post['city_id']]['name'].'-'; } if(in_array('district',$name_rule)) { $store_name.=$regions[$post['district_id']]['name'].'-'; } if(in_array('street',$name_rule)) { $store_name.=$street_name.'-'; } if(in_array('no',$name_rule)) { //取最新的编号 $no=$setting['name_rule_no']; $has=HappinessStore::find() ->where(['mall_id'=>$this->mall_id]) ->orderBy('id desc') ->asArray() ->one(); if(!empty($has)) { $no=$has['no']; } $number = intval($no) + 1; $post['no'] = str_pad($number, strlen($no), '0', STR_PAD_LEFT); $store_name.=$post['no'].'-'; } $post['store_name'] = $store_name.$post['store_name']; } else { return $this->error('请设置小店命名规则'); } $store = HappinessStore::addStore($post); if (false === $store) { return $this->error(HappinessStore::getStaticError()); } if (!empty($store)) { $params = [ 'mall_id' => $store['mall_id'], 'user_id' => $store['user_id'], 'store_id' => $store['id'], 'remark' => '后台新增门店添加', ]; $res = HappinessClerk::setData($params); } // } return $this->success('添加成功'); } } /** * @name: * @msg: 门店详情 * @param {*} * @return {*} */ public function actionDetail() { if (!\Yii::$app->request->isAjax) { return $this->render('/store/detail'); } if (\Yii::$app->request->isGet) { $store_id = \Yii::$app->request->get('store_id'); if (empty($store_id)) { return $this->error('参数错误'); } $store = HappinessStore::find() ->where(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED], 'id' => $store_id]) ->asArray() ->one(); if (empty($store)) { return $this->error('门店不存在'); } $streets = Town::find() ->where(['district_id'=>$store['district_id']]) ->select('id,name') ->asArray() ->indexBy('id') ->all(); $street_name = $streets[$store['street_id']]['name']??''; $region_ids = [$store['province_id'], $store['city_id'], $store['district_id']]; $regions = Region::find() ->select('id,name') ->where(['id' => $region_ids]) ->asArray() ->indexBy('id') ->all(); $store['addr'] = $regions[$store['province_id']]['name'] . '/' . $regions[$store['city_id']]['name'] . '/' . $regions[$store['district_id']]['name'].'/' . $street_name; $good_counts = HappinessStoreGoods::find() ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'store_id' => $store_id]) ->count(); $store['good_counts'] = $good_counts; $store['total_order_number'] = $store['total_num']; $store['unsettled_amount'] = $store['total_expenses']; $store['show_address'] = $regions[$store['province_id']]['name'] . $regions[$store['city_id']]['name'] . $regions[$store['district_id']]['name'] .$street_name.$store['address']; $basic_setting = $store; $store_admin = HappinessStoreAdmin::findOne(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'store_id' => $store_id]); $store_setting = [ 'shop_status' => $store['shop_status'] ?? 0, 'business_time_start' => $store['business_time_start'] ?? '', 'business_time_end' => $store['business_time_end'] ?? '', 'username' => $store_admin->username, 'merchant_distribution' => $store['merchant_distribution'] ?? 1, 'self_mention' => $store['self_mention'] ?? 1, ]; // if (!empty($basic_setting['freight_type'])) $store_setting['freight_type'] = json_decode($basic_setting['freight_type'], true); if (!empty($basic_setting['intra_city_distribution'])) $store_setting['intra_city_distribution'] = json_decode($basic_setting['intra_city_distribution'], true); $setting = \Yii::$app->services->setting->addons->get($this->mall_id, HappinessEnum::ADDONS_NAME, 'basic'); $configs = [ 'delivery_amount' => $setting['delivery_amount'], //起送金额 'delivery_fee' => $setting['delivery_fee'], //配送费设置 'start_limit' => $setting['start_limit'], //初始公里数 'start_amount' => $setting['start_amount'], //初始配送费 'add_limit' => $setting['add_limit'], //每次增加配送费公里数 'add_amount' => $setting['add_amount'], //每次增加配送费数量 ]; if ($setting['is_location_limit'] == 1) { $configs['localtion_limit'] = $setting['localtion_limit']; } else { $configs['localtion_limit'] = ''; } //赋值省市区街道等详情信息 $regions_provinces = Region::find() ->select('id,name') ->where(['level' => 1]) ->asArray() ->indexBy('id') ->all(); return $this->success('success', ['basic_setting' => $basic_setting, 'store_setting' => $store_setting, 'provinces' => $regions_provinces, 'configs' => $configs]); } else { $post = \Yii::$app->request->post(); $group = $post['group']; $store_id = $post['store_id']; if (empty($group) || !in_array($group, ['store_setting', 'cashier_setting', 'basic_setting']) || empty($store_id)) { return $this->error('参数错误'); } // dd($post[$group]); $rules = [ 'basic_setting' => [ [['store_name', 'logo_img', 'license_img', 'longitude', 'latitude', 'address'], 'string', 'max' => 255], [['shop_mobile', 'expire_time', 'province_id', 'city_id', 'district_id','street_id'], 'integer'], ], 'store_setting' => [ [['shop_status', 'business_time_start', 'business_time_end', 'username'], 'required'], [['shop_status', 'merchant_distribution', 'self_mention'], 'integer'], [['business_time_start', 'business_time_end', 'username'], 'string'], [['password', 'repassword', 'freight_type', 'intra_city_distribution'], 'safe'], ], ]; $res = \Yii::$app->services->validate->validate($post[$group], $rules[$group]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $post[$group]['store_id'] = $store_id; if ('store_setting' == $group) { $setting = \Yii::$app->services->setting->addons->get($this->mall_id, HappinessEnum::ADDONS_NAME, 'basic'); $post[$group]['is_alone'] = $post[$group]['intra_city_distribution']['is_alone']; if ($post[$group]['is_alone'] == 1) { $post[$group]['distribution_scope'] = $post[$group]['intra_city_distribution']['distribution_scope']; } else if ($post[$group]['is_alone'] == 0) { $post[$group]['distribution_scope'] = $setting['localtion_limit'] ? $setting['localtion_limit'] : 100000; if ($setting['is_location_limit'] == 0) $post[$group]['distribution_scope'] = 100000; } $res = HappinessStore::saveStoreSetting($this->mall_id, $post[$group]); if (false === $res) { return $this->error(HappinessStore::getStaticError()); } return $this->success('保存成功'); } elseif ('basic_setting' == $group) { $post[$group]['mall_id'] = $this->mall_id; $post[$group]['id'] = $store_id; unset($post[$group]['store_id']); // dd($post); // $addr = $post[$group]['address'] ?? ''; // if (!empty($addr)) { // $addrs = explode('/', $addr); // if(!empty($addrs[0])&&!empty( $addrs[1])&&!empty( $addrs[2])){ // $addrs[0] = str_replace('中国','',$addrs[0]); // $regions = Region::find() // ->select('id,name,level') // ->where(['or', ['name' => $addrs[0]], ['name' => $addrs[1]], ['name' => $addrs[2]]]) // ->asArray() // ->indexBy('level') // ->all(); // $post[$group]['province_id'] = $regions[1]['id']; // $post[$group]['city_id'] = $regions[2]['id']; // $post[$group]['district_id'] = $regions[3]['id']; // } // } $res = HappinessStore::setData($post[$group]); if (false === $res) { return $this->error(HappinessStore::getStaticError()); } return $this->success('保存成功'); } } } /** * 组件获取店铺列表 * @Author: lun * @DateTime: 2022/8/3 0003 18:40 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionStoreList() { $retuest = \Yii::$app->request; if ($retuest->isAjax) { if ($retuest->isGet) { $get = \Yii::$app->request->get(); // 检查提交的参数 $res = \Yii::$app->services->validate->validate($get, [ [['id'], 'integer'], [['store_name'], 'string'], [['store_ids', 'exist_ids'], 'safe'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $where = $list = []; !empty($get['id']) && $where[] = ['=', 'id', $get['id']]; $where[] = ['=', 'mall_id', $this->mall_id]; !empty($get['store_name']) && $where[] = ['like', 'store_name', $get['store_name']]; !empty($get['store_ids']) && $where[] = ['id' => $get['store_ids']]; !empty($get['exist_ids']) && $where[] = ['not in', 'id', $get['exist_ids']]; $where[] = ['=', 'check_status', StatusEnum::ENABLED]; $where[] = ['=', 'status', StatusEnum::ENABLED]; $order = 'created_at desc'; $select = 'id,c_id,mall_id,logo_img,store_name,shop_mobile,created_at'; $params = array('where' => $where, 'select' => $select, 'order' => $order, 'limit' => $get['limit']); $params['with'] = ['cate' => function ($query) { $query->select('id, name'); }]; $list = HappinessStore::listPage($params, false, true); return $this->success('获取成功', $list); } } } /** * 选择门店接口,外部调用 * @return mixed|void */ public function actionSelectStore() { if (Yii::$app->request->isAjax && Yii::$app->request->isGet) { $params = Yii::$app->request->get(); $params['where'][] = ['mall_id' => $this->mall_id]; $params['where'][] = ['status' => [StatusEnum::ENABLED]]; if (!empty($params['keyword'])) $params['where'][] = ['or', ['like', 'store_name', $params['keyword']], ['id' => $params['keyword']]]; $params['order'] = 'id desc'; $params['select'] = 'id,store_name,shop_owner,shop_mobile,logo_img,store_desc,shop_status,status'; $list = HappinessStore::listPage($params); return $this->success('操作成功', $list); } } //门店删除 public function actionDel() { try { $params = Yii::$app->request->post(); HappinessStore::delStore($this->mall_id, $params['id']); return $this->success(); } catch (\Exception $e) { return $this->error($e->getMessage()); } } //发放提货券 public function actionRecharge() { try { $params = Yii::$app->request->post(); $number = $params['number'];//充值的金额 $store_id = $params['store_id'];//门店id $recharge_list = \Yii::$app->services->setting->addons->get($this->mall_id, HappinessEnum::ADDONS_NAME, 'basic.recharge_list'); $recharge_list = !empty($recharge_list) ? json_decode($recharge_list, true) : []; if (empty($recharge_list)) { throw new \Exception('请先配置充值金额'); } $itemSetting = []; foreach ($recharge_list as $item) { if ($item['number'] == $number) { $itemSetting = $item; break; } } if (empty($itemSetting) || empty($itemSetting['items'])) { throw new \Exception('请先配置充值金额'); } $wallet_log = []; foreach ($itemSetting['items'] as $item) { $wallet_log[] = [ 'mall_id' => $this->mall_id, 'store_id' => $store_id, 'level' => $item['level'], 'change_type' => CapitalLog::CHANGE_TYPE_ADD, 'change_num' => $item['price'], 'desc' => '管理员后台充值', 'source_table' => HappinessVoucherWallet::tableName(), 'source_table_id' => $store_id, 'from_type' => HappinessVoucherEnum::SYSTEM_ADD, 'wallet_type' => HappinessVoucherEnum::WALLET_VALUE, 'status' => 1, 'order_no' => '' ]; } if(!empty($wallet_log)) { foreach ($wallet_log as $item) { try { $res=WalletLogic::handle($item); } catch (\Exception $e) { \Yii::error($e->getMessage()); } if($res===false) { throw new \Exception(WalletLogic::getStaticError()); } } } return $this->success('操作成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } }