id; if ($admin->username == 'admin' || $admin->type == Admin::ADMIN_TYPE_SAAS_STAFF) { $admin_id = null; } $form->id = get_params("id"); $form->name = get_params("name"); $form->mobile = get_params("mobile"); $form->user_name = get_params("user_name"); $form->category_id = get_params("category_id", -1); $form->status = get_params('status', -1); $form->business_model = get_params('business_model', -1); $form->province_id = get_params('province_id'); $form->city_id = get_params('city_id'); $form->district_id = get_params('district_id'); $form->start_time = get_params('start_time'); $form->end_time = get_params('end_time'); $form->integral_profit_status = get_params('integral_profit_status'); $result = $form->getList($admin_id); return $this->asJson($result); } //申请单列表 public function actionGetAuditList() { $form = new StoreForm(); $form->name = get_params("name"); $form->admin_id = get_params("admin_id", 0); $form->salesman_id = get_params("salesman_id", 0); $form->status = get_params("status", -1); $result = $form->getAuditList(); return $this->asJson($result); } //申请审核 public function actionStoreAudit() { $form = new StoreForm(); $form->id = post_params("id", 0); $form->status = post_params("status", -1); $form->business_model = post_params("business_model", -1); $form->qrcode_id = post_params("qrcode_id", -1); $result = $form->storeAudit(); return $this->asJson($result); } //店铺初始化 public function actionStoreInit() { $id = input_params("id", 0); $default = \app\models\Option::get('store_template_default', 0, 'saas', null)['value']; if($default){ $default = json_decode($default, true); }else{ return $this->asJson([ 'code' => 0, 'msg' => '暂无默认模板', ]); } $id = \queue_push(new StoreSyncJob(['type' => 1, 'to_id' => $id]), 0, 1); // $res = StoreCopy::doCopy($default['store_id'], $id, $default['type']); // return $this->asJson($res); return $this->asJson([ 'code' => 0, 'msg' => '操作成功' ]); } // public function actionGetQrcode() { $form = new StoreForm(); $form->business_model = post_params("business_model"); $res = $form->getQrcode(); return $this->asJson($res); } //绑定业务员 public function actionBindSalesman() { $form = new StoreForm(); $form->id = post_params("id", 0); $form->salesman_id = post_params("salesman_id", -1); $result = $form->bindSalesman(); return $this->asJson($result); } /** * @return \yii\web\Response * 获取没有成为云仓的商城 */ public function actionGetList() { $form = new StoreForm(); $result = $form->getStoreList(); return $this->asJson($result); } /** * 添加商城 */ public function actionAdd() { $saas_user_id = post_params('saas_user_id'); $name = post_params('name'); $username = post_params('username'); $password = post_params('password'); $area = post_params('area'); $logo = post_params('logo'); // $store_number= post_params('storeNumber'); $form = new StoreForm(); return $this->asJson($form->add($name, $password, $username, $area, $saas_user_id, $logo, 0)); } public function actionSetData() { $form = new StoreForm(); return $this->asJson($form->initStoreData()); } /** * 修改密码 */ public function actionSetPassword() { $form = new StoreForm(); if (\Yii::$app->request->isPost) { $store_id = post_params('store_id'); $password = post_params("password"); $name = post_params("name"); $username = post_params("username"); $saas_user_id = post_params("saas_user_id"); $res = $form->setPassword($store_id, $password, $name, $username, $saas_user_id); } else { $store_id = get_params('store_id'); $admin = Admin::findOne([ 'type' => 'store', 'type_id' => $store_id ]); $saas_user = SaasUser::findOne($admin->saas_user_id); $store = Store::findOne($store_id); $res = [ 'code' => 0, 'msg' => '获取成功', 'data' => [ 'name' => $admin->name, 'username' => $admin->username, 'saas_user_id' => $admin->saas_user_id, 'saas_user' => $saas_user, ] ]; } return $this->asJson($res); } /** * 删除商城 */ public function actionDel() { $store_id = post_params('store_id'); $form = new StoreForm(); return $this->asJson($form->delete($store_id)); } /** * 设置saas分销参数 */ public function actionSetShareParams() { $store_id = post_params('storeId') ?: post_params('store_id'); $params = [ 'level' => post_params('level', 0), 'is_rebate' => post_params('is_rebate', 0), 'price_type' => post_params('price_type', 0), 'level_one' => post_params('level_one', 0), 'level_two' => post_params('level_two', 0), 'level_three' => post_params('level_three', 0), ]; $form = new StoreForm(); return $this->asJson($form->setShareParams($store_id, $params)); } /** * 设置商铺开通续费金额信息 */ // public function actionSetStoreCost(){ // $store_id = post_params('storeId') ?: post_params('store_id'); // $params = [ // 'open_price' => post_params('open_price', 0), // 'renew_price' => post_params('renew_price', 0), // 'end_time' => strtotime(post_params('end_time')), // 'profit' => post_params('profit', 0), // 'is_use_default' => post_params('is_use_default', 1), // ]; // $form = new StoreForm(); // return $this->asJson($form->setCost($store_id, $params)); // } /** * 获取商铺开通续费金额信息 */ public function actionGetStoreCost() { $store_id = get_params('storeId'); $form = new StoreForm(); return $this->asJson($form->getCost($store_id)); } /** * 缴纳商铺费用逻辑 */ public function actionPayFee() { $store_id = get_params('storeId'); $form = new StoreForm(); return $this->asJson($form->payFee($store_id)); } /** * 判断是否缴纳成功 */ public function actionGetIsPay() { $order_id = get_params('order_id'); $form = new StoreForm(); return $this->asJson($form->isPay($order_id)); } /** * 获取店铺续费订单 */ public function actionStoreReOrder() { $store_id = get_params('store_id'); $form = new StoreForm(); $form->attributes = get_params(); return $this->asJson($form->reOrderList($store_id)); } /** * 获取saas分销参数 */ public function actionGetShareParams() { $store_id = get_params('storeId'); $form = new StoreForm(); return $this->asJson($form->getShareParams($store_id)); } /** * 获取推荐人信息 */ public function actionGetReferralParams() { $store_id = get_params('storeId'); $form = new StoreForm(); return $this->asJson($form->getReferralParams($store_id)); } /** * 设置推荐人信息 */ public function actionSetReferralParams() { $store_id = post_params('storeId'); $params = post_params('lists'); $form = new StoreForm(); return $this->asJson($form->setReferralParams($store_id, $params)); } /** * 获取商城返利比例 */ public function actionGetTransferProfitParams() { $store_id = get_params('storeId'); $form = new StoreForm(); return $this->asJson($form->getTransferProfitParams($store_id)); } /** * 设置商城返利比例 */ public function actionSetTransferProfitParams() { $store_id = post_params('storeId'); $params = [ 'transfer_profit' => post_params('transfer_profit', 0), 'scan_transfer_profit' => post_params('scan_transfer_profit', 0), 'food_transfer_profit' => post_params('food_transfer_profit', 0), 'cashier_transfer_profit' => post_params('cashier_transfer_profit', 0), ]; $form = new StoreForm(); return $this->asJson($form->SetTransferProfitParams($store_id, $params)); } /** * 获取商城基本信息 */ public function actionGetStoreInfo() { $store_id = get_params('storeId', get_store_id()); $form = new StoreForm(); return $this->asJson($form->getInfo($store_id)); } public function actionJoinAlliance() { $store_id = post_params('storeId', get_store_id()); $status = post_params('status'); $form = new StoreForm(); return $this->asJson($form->joinAlliance($store_id, $status)); } public function actionGetCheckList() { $form = new StoreForm(); return $this->asJson($form->getCheckList()); } public function actionDouyinInfo() { $form = new StoreForm(); $store_id = get_params('storeId', get_store_id()); if (\Yii::$app->request->isPost) { $content = post_params('content', ''); $params = [ 'app_id' => post_params('app_id', ''), 'app_secret' => post_params('app_secret', ''), 'salt' => post_params('salt', ''), 'token' => post_params('token', '') ]; return $this->asJson($form->setDouyinInfo($store_id, $content, $params)); } return $this->asJson($form->getDouyinInfo($store_id)); } /** * 获取商城参数 */ public function actionGetStoreParams() { $store_id = get_params('storeId'); $form = new StoreForm(); return $this->asJson($form->getStoreParams($store_id)); } /** * 设置商城参数 */ public function actionSetStoreParams() { $store_id = post_params('storeId'); $params = [ 'name' => post_params('name', ''), 'balance' => post_params('balance', 0), 'logo' => post_params('logo', ''), 'coordinate' => post_params('coordinate', ''), 'address' => post_params('address', ''), 'category_id' => post_params('category_id', 0), 'category_option' => post_params('category_option', []), 'address_info' => post_params('address_info'), 'area' => post_params('area'), 'sales' => post_params('sales', 0), 'rank' => post_params('rank', 5), 'per_spend' => post_params('per_spend', 0), 'tags' => post_params('tags', []), 'user_name' => post_params('user_name', ''), 'contact_tel' => post_params('contact_tel', ''), 'start_time' => post_params('start_time', '00:00'), 'end_time' => post_params('end_time', '23:59'), 'open_status' => post_params('open_status', 1), 'shop_time_type' => post_params('shop_time_type', 0), 'is_time_forbid' => post_params('is_time_forbid', 1), 'is_set_distance' => post_params('is_set_distance', 0), 'distance' => post_params('distance', 0), 'store_admin' => post_params('store_admin', 0), 'business_model' => post_params('business_model', 0), 'self_mini' => post_params('self_mini', 0), 'store_permission' => post_params('store_permission', []), 'cost_end_time' => post_params('cost_end_time', []), 'salesman_id' => post_params('salesman_id', 0), 'is_add_goods' => post_params('is_add_goods', 1), 'mini_auth_num' => post_params('mini_auth_num', 0), 'is_store_traffic_sharing' => post_params('is_store_traffic_sharing', 0), ]; $form = new StoreForm(); return $this->asJson($form->setStoreParams($store_id, $params)); } /** * 获取商城类目数据 */ public function actionGetCategoryInfo() { $categoryForm = new SaasCategoryForm(); return $this->asJson($categoryForm->getList(false)); } /** * 自定义表单 * @return array|mixed|\yii\web\Response */ public function actionForm() { $store_id = get_store_id(); $form_list = Form::find()->where(['is_delete' => 0, 'store_id' => $store_id])->orderBy(['sort' => SORT_ASC])->asArray()->all(); if (\Yii::$app->request->isPost) { $form = new SubmitFormForm(); $form->store_id = $store_id; $form->attributes = post_params(); return $this->asJson($form->save()); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'form_list' => $form_list, 'is_form' => intval(Option::get('is_form', $store_id, 'store', 0)['value']), 'form_name' => Option::get('form_name', $store_id, 'store', '表单名称')['value'] ] ]); } /** * @return \yii\web\Response */ public function actionGetDeliveryInfo() { $store_id = get_store_id(); $result = Option::getDeliveryConfig(); $store = Store::findOne($store_id); $category_one = $category_two = ''; if ($store->delivery_category) { $arr = explode(',', $store->delivery_category); $category_one = $arr[0]; $category_two = $arr[1]; } //判断是否设置地区、地址、坐标、联系人、联系方式 ,否则跳转 $is_jump = 0; if (empty($store->address) || empty($store->province_id) || empty($store->city_id) || empty($store->district_id) || empty($store->contact_tel) || empty($store->user_name)) { $is_jump = 1; } $data = [ 'type' => $store->delivery_type, 'config' => $result, 'wechat_msg_token' => $store->wechat_msg_token ?: '', 'category_one' => $category_one, 'category_two' => $category_two, 'category_level_one' => Delivery::$validLevelOneCategory, 'category_level_list' => Delivery::$validLevelCategory, 'is_jump' => $is_jump, 'wechat_delivery_type' => $store->wechat_delivery_type ]; $keys = [ 'local_sym_sn', 'local_sym_key', 'rsa_sn', 'rsa_private_key' ]; $delivery_data = Option::get($keys, $store_id, 'delivery'); if (empty($delivery_data)) { $delivery_data = [ 'local_sym_sn' => '', 'local_sym_key' => '', 'rsa_sn' => '', 'rsa_private_key' => '' ]; } else { $arr = []; foreach ($delivery_data as $value) { $index = array_search($value['name'], $keys); unset($keys[$index]); $arr[$value['name']] = $value['value']; } foreach ($keys as $key) { $arr[$key] = ''; } $delivery_data = $arr; } $data = array_merge($data, $delivery_data); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data ]); } /** * @return \yii\web\Response */ public function actionSetDeliveryInfo() { $delivery_shop_id = trim(post_params('delivery_shop_id')); $delivery_app_secret= trim(post_params('delivery_app_secret')); $delivery_shop_no = trim(post_params('delivery_shop_no' ,'')); $type = trim(post_params('type')); $wechat_msg_token = trim(post_params('wechat_msg_token')); $delivery_category_one = post_params('category_one'); $delivery_category_two = post_params('category_two'); $wechat_delivery_type = post_params('wechat_delivery_type', 0);//0即时配送 1同城配送 $local_sym_sn = post_params('local_sym_sn', '');//对称密钥编号 $local_sym_key = post_params('local_sym_key', '');//对称密钥密钥明文 $rsa_sn = post_params('rsa_sn', '');//非对称密钥编号 $rsa_private_key = post_params('rsa_private_key', '');//非对称密钥私玥 $store_id = get_store_id(); $store = Store::findOne($store_id); $store->wechat_delivery_type = $wechat_delivery_type; $store->save(); if (intval($wechat_delivery_type) === 0) { if (empty($delivery_shop_id) || empty($delivery_app_secret) || empty($delivery_shop_no) || empty($wechat_msg_token) || empty($delivery_category_one) || empty($delivery_category_two) || empty($type)) { return $this->asJson([ 'code' => 1, 'msg' => '参数有误' ]); } $res = Delivery::getBindAccount(); if ($res['code'] > 0) { if ($res['code'] == 48001) { return $this->asJson([ 'code' => 1, 'msg' => '请在微信小程序后台开通即时配送物流服务' ]); } } if (empty($res['data']['shop_list'])) { return $this->asJson([ 'code' => 1, 'msg' => '当前未绑定运力账号,暂不能保存选择同城配送方式', '$res' => $res, ]); } $shop_list = $res['data']['shop_list']; $delivery_arr = array_column($shop_list, 'delivery_id'); $delivery_arr_id = array_column($shop_list, null, 'delivery_id'); if (!in_array(Delivery::$deliveryIdArr[$type], $delivery_arr) || $delivery_arr_id[Delivery::$deliveryIdArr[$type]]['audit_result'] != 0) { return $this->asJson([ 'code' => 1, 'msg' => '当前账号未在微信后台绑定或者并未审核通过' ]); } if ($type == 1) { Option::set('sf_app_key', $delivery_shop_id, $store_id, 'store'); Option::set('sf_app_secret', $delivery_app_secret, $store_id, 'store'); Option::set('sf_shop_no', $delivery_shop_no, $store_id, 'store'); } if ($type == 2) { Option::set('dd_app_key', $delivery_shop_id, $store_id, 'store'); Option::set('dd_app_secret', $delivery_app_secret, $store_id, 'store'); Option::set('dd_shop_no', $delivery_shop_no, $store_id, 'store'); } if ($type == 3) { Option::set('ss_app_key', $delivery_shop_id, $store_id, 'store'); Option::set('ss_app_secret', $delivery_app_secret, $store_id, 'store'); Option::set('ss_shop_no', $delivery_shop_no, $store_id, 'store'); } if ($type == 4) { Option::set('mt_app_key', $delivery_shop_id, $store_id, 'store'); Option::set('mt_app_secret', $delivery_app_secret, $store_id, 'store'); Option::set('mt_shop_no', $delivery_shop_no, $store_id, 'store'); } if ($type == 5) { Option::set('uu_app_key', $delivery_shop_id, $store_id, 'store'); Option::set('uu_app_secret', $delivery_app_secret, $store_id, 'store'); Option::set('uu_shop_no', $delivery_shop_no, $store_id, 'store'); } $store->delivery_type = $type; $store->wechat_msg_token = $wechat_msg_token; $store->delivery_category = $delivery_category_one . ',' . $delivery_category_two; if ($store->save()) { return $this->asJson([ 'code' => 0, 'msg' => 'success', ]); } } else { $keys = [ 'local_sym_sn', 'local_sym_key', 'rsa_sn', 'rsa_private_key' ]; $data = [ $local_sym_sn, $local_sym_key, $rsa_sn, $rsa_private_key ]; Option::set($keys, $data, $store_id, 'delivery'); return $this->asJson([ 'code' => 0, 'msg' => 'success', ]); } return $this->asJson([ 'code' => 1, 'msg' => $store->errors[0], ]); } public function actionFoodSettingInfo() { $store_id = get_store_id(); $mch_id = intval(get_mch_id()); $store = Store::findOne($store_id); if($mch_id){ $store = Mch::findOne($mch_id); } if (!$store->food_payment) { $payment = [ [ 'key' => 'alipay', 'value' => 0, 'name' => '' ], [ 'key' => 'wechat', 'value' => 1, 'name' => '' ], [ 'key' => 'huodao', 'value' => 0, 'name' => '' ], [ 'key' => 'friend', 'value' => 0, 'name' => '' ], ]; $store->food_payment = Json::encode($payment); $store->save(); } $default_food_delivery = (int)Option::get('default_food_delivery', $store_id, 'store', 0)['value']; //到店自提 //点餐页面标题 $food_page_title = Option::get('food_page_title', $store_id, 'store', '')['value']; if($mch_id){ $food_open_time = Option::get('food_open_time', $mch_id, 'mch', '')['value']; $default_food_delivery = (int)Option::get('default_food_delivery', $mch_id, 'mch', 0)['value']; //到店自提 $food_page_title = Option::get('food_page_title', $mch_id, 'mch', '')['value']; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'food_payment' => Json::decode($store->food_payment), 'food_pay_type' => $store->food_pay_type, 'food_open_time' => $food_open_time, 'default_food_delivery' => $default_food_delivery, 'food_page_title' => $food_page_title ?: '手机点餐' ] ]); } public function actionFoodSetting() { $store_id = get_store_id(); $mch_id = intval(get_mch_id()); $store = Store::findOne($store_id); $payment = post_params('food_payment'); $pay_type = post_params('food_pay_type', 0); $food_page_title = post_params('food_page_title'); $default_food_delivery = post_params('default_food_delivery', 0); if($mch_id){ $store = Mch::findOne($mch_id); Option::set('default_food_delivery', $default_food_delivery, $mch_id, 'mch'); $food_open_time = post_params('food_open_time', ''); Option::set('food_open_time', $food_open_time, $mch_id, 'mch'); Option::set('food_page_title', $food_page_title, $mch_id, 'mch'); }else{ Option::set('default_food_delivery', $default_food_delivery, $store_id, 'store'); Option::set('food_page_title', $food_page_title, $store_id, 'store'); } $store->food_pay_type = $pay_type; $store->food_payment = $payment; if (!$store->save()) { return $this->asJson([ 'code' => 1, 'msg' => $store->errors ]); } return $this->asJson([ 'code' => 0, 'msg' => '保存成功' ]); } public function actionChangeJoinUnionStatus() { $id = post_params('id'); $status = post_params('status'); if (!$id) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误' ]); } if (!in_array($status, [0, 1])) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误' ]); } $store = Store::findOne($id); if (!$store) { return $this->asJson([ 'code' => 1, 'msg' => '商城未找到' ]); } $store->is_alliance = $status; $store->save(); return $this->asJson([ 'code' => 0, 'msg' => '保存成功' ]); } // app设置 public function actionSettingApp() { $store_id = get_store_id(); if (\Yii::$app->request->isPost) { $client_privacy_id = post_params('client_privacy_id', ''); $client_service_id = post_params('client_service_id', ''); $app_down_android = post_params('app_down_android', ''); $app_down_ios = post_params('app_down_ios', ''); Option::set('client_privacy_id', $client_privacy_id, $store_id, 'app'); Option::set('client_service_id', $client_service_id, $store_id, 'app'); Option::set('app_down_android', $app_down_android, $store_id, 'app'); Option::set('app_down_ios', $app_down_ios, $store_id, 'app'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } $data = [ 'client_privacy_id' => Option::get('client_privacy_id', $store_id, 'app', '')['value'], 'client_service_id' => Option::get('client_service_id', $store_id, 'app', '')['value'], 'app_down_android' => Option::get('app_down_android', $store_id, 'app', '')['value'], 'app_down_ios' => Option::get('app_down_ios', $store_id, 'app', '')['value'], ]; return $this->asJson([ 'code' => 0, 'data' => $data, 'msg' => 'success', ]); } // 版权设置 public function actionCopyrightSetting() { $store_id = get_store_id(); if (\Yii::$app->request->isPost) { $web_name = post_params('web_name', ''); $web_log = post_params('web_log', ''); $copyright = post_params('copyright', ''); $help_logo = post_params('help_logo', ''); $describe = post_params('describe', ''); $passport_bg = post_params('passport_bg', ''); $store_share_title = post_params('store_share_title', ''); $store_share_logo = post_params('store_share_logo', ''); $store_share_desc = post_params('store_share_desc', ''); Option::set('web_name', $web_name, $store_id, 'web'); Option::set('web_log', $web_log, $store_id, 'web'); Option::set('copyright', $copyright, $store_id, 'web'); Option::set('help_logo', $help_logo, $store_id, 'web'); Option::set('describe', $describe, $store_id, 'web'); Option::set('passport_bg', $passport_bg, $store_id, 'web'); // Option::set('store_share_title', $store_share_title, $store_id, 'web'); // Option::set('store_share_logo', $store_share_logo, $store_id, 'web'); // Option::set('store_share_desc', $store_share_desc, $store_id, 'web'); $store = Store::findOne($store_id); if ($store) { if ($web_name) { $store->name = $web_name; } if ($web_log) { $store->logo = $web_log; } $store->save(); } return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } $data = [ 'web_name' => Option::get('web_name', $store_id, 'web', '')['value'], 'web_log' => Option::get('web_log', $store_id, 'web', '')['value'], 'copyright' => Option::get('copyright', $store_id, 'web', '')['value'], 'passport_bg' => Option::get('passport_bg', $store_id, 'web', '')['value'], 'help_logo' => Option::get('help_logo', $store_id, 'web', '')['value'], 'describe' => Option::get('describe', $store_id, 'web', '')['value'], // 'store_share_title' => Option::get('store_share_title', $store_id, 'web', '')['value'], // 'store_share_logo' => Option::get('store_share_logo', $store_id, 'web', '')['value'], // 'store_share_desc' => Option::get('store_share_desc', $store_id, 'web', '')['value'], ]; return $this->asJson([ 'code' => 0, 'data' => $data, 'msg' => 'success', ]); } /** * 积分设置 * @return \yii\web\Response */ public function actionIntegralSetting() { $store_id = get_store_id(); $data = [ 'register_rule' => '', 'register_integral' => '1', 'register_integral_end' => '5', 'register_continuation' => 0, 'register_reward' => '1', 'register_reward_end' => '10', 'register_status' => 1 ]; $integral_setting = IntegralSetting::findOne(['store_id' => $store_id]); $integral_setting['register_integral_end'] = $integral_setting['register_integral_end'] ?? '5'; $integral_setting['register_reward_end'] = $integral_setting['register_reward_end'] ?? '5'; $integral_setting['register_status'] = (int)$integral_setting['register_status']; return $this->asJson( [ 'code' => 0, 'msg' => 'success', 'data' => $integral_setting ?: $data ] ); } /** * 积分设置保存 * @return \yii\web\Response */ public function actionIntegralSettingSave() { $register_status = post_params('register_status', 1); $register_rule = post_params('register_rule', ''); $register_integral = post_params('register_integral', 1); $register_continuation = post_params('register_continuation', 0); $register_reward = post_params('register_reward', 1); $register_integral_end = post_params('register_integral_end', 5); $register_reward_end = post_params('register_reward_end', 5); $integral_setting = IntegralSetting::findOne(['store_id' => get_store_id()]); if ($register_integral < 1 || $register_reward_end < 1) { return $this->asJson([ 'code' => 1, 'msg' => '积分需大于0' ]); } if ($register_integral_end < $register_integral) { return $this->asJson([ 'code' => 1, 'msg' => '每日签到获得分数区间错误' ]); } if ($register_reward_end < $register_reward) { return $this->asJson([ 'code' => 1, 'msg' => '连续签到奖励积分区间设置错误' ]); } $integral_setting = $integral_setting ?: new IntegralSetting(); $integral_setting->store_id = get_store_id(); $integral_setting->register_continuation = $register_continuation; $integral_setting->register_integral = $register_integral; $integral_setting->register_rule = $register_rule; $integral_setting->register_reward = $register_reward; $integral_setting->register_integral_end = $register_integral_end; $integral_setting->register_reward_end = $register_reward_end; $integral_setting->register_status = $register_status; if ($integral_setting->save()) { return $this->asJson([ 'code' => 0, 'msg' => '保存成功' ]); } else { return $this->asJson([ 'code' => 1, 'msg' => $integral_setting->errors[0] ]); } } /** * ocr接口调用参数配置 * @return \yii\web\Response */ public function actionOcrSetting() { $default = [ 'app_secret' => '', 'app_key' => '', ]; if (\Yii::$app->request->getIsPost()) { $content = post_params('content', $default); Option::set('ocr', json_encode($content), get_store_id(), 'store'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $content = Option::get('ocr', get_store_id(), 'store', json_encode($default)); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => json_decode($content['value']), ]); } } // 联盟券设置 public function actionSettingLeague() { $store_id = get_store_id(); if (\Yii::$app->request->isPost) { // $store_this_profit = post_params('store_this_profit', ''); $goods_send_profit = post_params('goods_send_profit', ''); $goods_take_price = post_params('goods_take_price', ''); $is_show_alliance_coupon = post_params('is_show_alliance_coupon', 0); // Option::set('store_this_profit', $store_this_profit, $store_id, 'store'); Option::set('goods_send_profit', $goods_send_profit, $store_id, 'store'); Option::set('goods_take_price', $goods_take_price, $store_id, 'store'); Option::set('is_show_alliance_coupon', $is_show_alliance_coupon, $store_id, 'store'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } $data = [ // 'store_this_profit' => Option::get('store_this_profit', $store_id, 'store', '')['value'], 'goods_send_profit' => Option::get('goods_send_profit', $store_id, 'store', '')['value'], 'goods_take_price' => Option::get('goods_take_price', $store_id, 'store', '')['value'], 'is_show_alliance_coupon' => Option::get('is_show_alliance_coupon', $store_id, 'store', 0)['value'], ]; return $this->asJson([ 'code' => 0, 'data' => $data, 'msg' => 'success', ]); } // 当面付分佣设置 public function actionSettingFacePayProfit() { $store_id = get_store_id(); if (\Yii::$app->request->isPost) { $face_first_profit = post_params('face_first_profit', ''); $face_second_profit = post_params('face_second_profit', ''); $face_third_profit = post_params('face_third_profit', ''); // $face_pay_path = post_params('face_pay_path'); // if (isset($face_pay_path)) { // $face_pay_path = json_encode($face_pay_path, JSON_UNESCAPED_UNICODE); // Option::set('face_pay_path', $face_pay_path, $store_id,'store'); // } $rate = post_params('rate'); $rate_type = post_params('rate_type'); if(isset($rate)){ Option::set('face_rate', $rate, $store_id, 'store'); Option::set('face_rate_type', $rate_type, $store_id, 'store'); } Option::set('face_first_profit', $face_first_profit, $store_id, 'store'); Option::set('face_second_profit', $face_second_profit, $store_id, 'store'); Option::set('face_third_profit', $face_third_profit, $store_id, 'store'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } $data = [ 'face_first_profit' => Option::get('face_first_profit', $store_id, 'store', '')['value'], 'face_second_profit' => Option::get('face_second_profit', $store_id, 'store', '')['value'], 'face_third_profit' => Option::get('face_third_profit', $store_id, 'store', '')['value'], 'rate' => Option::get('face_rate', $store_id, 'store')['value'], 'rate_type' => Option::get('face_rate_type', $store_id, 'store')['value'], // 'face_pay_path' => Option::get('face_pay_path', $store_id, 'store', '')['value'] ]; // $data['face_pay_path'] = json_decode($data['face_pay_path'], true) ?: null; return $this->asJson([ 'code' => 0, 'data' => $data, 'msg' => 'success', ]); } public function actionFaceMarketingProfit() { $store_id = get_store_id(); if (\Yii::$app->request->isPost) { $send_integral_profit = post_params('send_integral_profit', ''); Option::set('face_send_integral_profit', $send_integral_profit, $store_id, 'store'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } $data = [ 'send_integral_profit' => Option::get('face_send_integral_profit', $store_id, 'store', '0')['value'] ]; // $data['face_pay_path'] = json_decode($data['face_pay_path'], true) ?: null; return $this->asJson([ 'code' => 0, 'data' => $data, 'msg' => 'success', ]); } /** * 销售溢价比 */ public function actionStoreRate() { try { $store_id = get_store_id(); $store = Store::findOne($store_id); $data = []; if (\Yii::$app->request->isGet) { $cloud_is_update = Option::get('cloud_is_update', $store_id, 'store')['value']; $reduce_type = Option::get('reduce_type', $store_id, 'store')['value']; $sale_price_type = Option::get('sale_price_type', $store_id, 'store')['value']; $repeat_update_goods_price = Option::get('repeat_update_goods_price', $store_id, 'store')['value']; $store_cloud_send_type = Option::get('store_cloud_send_type', $store_id, 'store')['value']; $arr = [ 'rate' => $store->rate, // 'is_auth_trans' => $store->is_auth_trans, 'cloud_is_update' => (int)$cloud_is_update, 'reduce_type' => $reduce_type, 'sale_price_type' => (int)$sale_price_type, 'repeat_update_goods_price' => (int)$repeat_update_goods_price, 'store_cloud_send_type' => json_decode($store_cloud_send_type, true) ?: ['express'] ]; //自动优先扣除方式 $form = new MerchantForm(); $result = $form->setCloudMerchantConfig(); if ($result['code'] === 0) { $arr['reduce_type'] = (int)$result['data']['reduce_type']; } $data = [ 'code' => 0, 'msg' => "获取成功", 'data' => $arr ]; } elseif (\Yii::$app->request->isPost) { $rate = floatval(post_params('rate', 0)); $reduce_type = post_params('reduce_type', 0); // $is_auth_trans = post_params('is_auth_trans', 0); $cloud_is_update = post_params('cloud_is_update', 0); $sale_price_type = post_params('sale_price_type', 0); $repeat_update_goods_price = post_params('repeat_update_goods_price', 0); $store_cloud_send_type = post_params('store_cloud_send_type'); if (empty($store_cloud_send_type)) { throw new \Exception('请选择发货方式'); } if (!is_array($store_cloud_send_type)) { throw new \Exception('发货方式格式错误'); } $open = false; array_map(function ($item) use (&$open){ if (!in_array($item, ['express', 'shop', 'delivery'])) { $open = true; } }, $store_cloud_send_type); if ($open) { throw new \Exception('发货方式格错误'); } Option::set('sale_price_type', $sale_price_type, get_store_id(), 'store'); Option::set('cloud_is_update', $cloud_is_update, get_store_id(), 'store'); Option::set('reduce_type', $reduce_type, get_store_id(), 'store'); Option::set('repeat_update_goods_price', $repeat_update_goods_price, get_store_id(), 'store'); Option::set('store_cloud_send_type', json_encode($store_cloud_send_type, JSON_UNESCAPED_UNICODE), get_store_id(), 'store'); $store->rate = $rate; // $store->is_auth_trans = $is_auth_trans; if (!$store->save()) { throw new \Exception(json_encode($store->errors)); } //自动优先扣除方式 $form = new MerchantForm(); $result = $form->setCloudMerchantConfig($reduce_type); if ($result['code'] === 0) { $arr['reduce_type'] = (int)$result['data']['reduce_type']; } $data = [ 'code' => 0, 'msg' => "操作成功", ]; } return $this->asJson($data); } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage(), ]); } } /** * 获取设备ID和在线状态 * @return \yii\web\Response * @throws \yii\base\InvalidConfigException * @author Syan mzsongyan@gmail.com * @date 2022-06-02 */ public function actionGetVoiceDeviceInfo() { $store_id = get_store_id(); $store = Store::findOne($store_id); $deviceName = ''; $online = 0; if ($store->device_name) { $deviceName = $store->device_name; $result = IotCloudHelper::getDeviceInfo($store_id); if ($result['code'] == 0) { $online = $result['data']['Online']; } } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'device_name' => $deviceName, 'online' => $online, ], ]); } /** * 绑定设备 * @return \yii\web\Response|void * @author Syan mzsongyan@gmail.com * @date 2022-06-02 */ public function actionSetVoiceDeviceInfo() { try { $store_id = get_store_id(); $store = Store::findOne($store_id); $deviceName = post_params('device_name'); $type = post_params('type'); if($type == 'unbind'){ $oldDeviceName = $store->device_name; $store->device_name = ''; $store->save(); return $this->asJson([ 'code' => 0, 'msg' => '解绑成功,设备:' . $oldDeviceName, ]); } if (!$deviceName) { throw new \Exception('请输入设备ID'); } if ($deviceName == $store->device_name) { return $this->asJson([ 'code' => 0, 'msg' => '绑定成功', ]); } $exist = Store::find()->where(['device_name' => $deviceName])->andWhere(['<>', 'id', $store_id])->one(); if ($exist) { throw new \Exception('该设备ID已经被使用'); } $oldDeviceName = $store->device_name; $store->device_name = $deviceName; $store->save(); $result = IotCloudHelper::getDeviceInfo($store_id); if ($result['code'] == 1) { $store->device_name = $oldDeviceName; $store->save(); throw new \Exception('设备ID不正确或设备未开机'); } return $this->asJson([ 'code' => 0, 'msg' => '绑定成功', ]); } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage(), ]); } } public function actionTestVoiceDevice() { try { $type = post_params('type', 1); $store_id = get_store_id(); $name = '微信'; if ($type == 2) { $name = '支付宝'; } $msg = '{"cmd":"voice","msg":"'. $name .'收款999元"}'; $result = IotCloudHelper::sendMessage($store_id, $msg); \Yii::error($result); if ($result['code'] == 1) { throw new \Exception($result['msg']); } return $this->asJson([ 'code' => 0, 'msg' => '发送成功', ]); } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage(), ]); } } //获取业务员列表 public function actionSalesmanList() { try { //如果是代理商登陆 $admin = get_admin(); $admin_id = $admin->id; if ($admin->username == 'admin') { $admin_id = null; } $query = Salesman::find()->alias('s')->leftJoin(['su' => SaasUser::tableName()], 's.saas_user_id = su.id'); if ($admin_id) { $query->where(['s.admin_id' => $admin_id]); } $salesman = $query->andWhere(['su.is_delete' => 0, 's.is_delete' => 0, 's.status' => 1, 's.type' => 1])->select('s.id, su.name, su.avatar')->asArray()->all(); return $this->asJson([ 'code' => 0, 'data' => [ 'list' => $salesman ] ]); } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } public function actionStoreCopyStatus() { $id = input_params('id', 0); $do = input_params('do', 0); $res = StoreCopy::doCopyStatus($id, $do); return $this->asJson($res); } public function actionStoreCopy() { $from_store_id = input_params('from_store_id', 0); $to_store_id = input_params('to_store_id', 0); $type = input_params('type', ['home']); $type = json_encode($type); $model = new \app\models\StoreCopy(); $model->from_store_id = $from_store_id; $model->to_store_id = $to_store_id; $model->type = $type; $model->save(); $id = queue_push(new \app\jobs\StoreCopyJob(['id' => $model->id])); $res = [ 'code' => 0, 'msg' => '数据量太大,请等待执行', 'id' => $id ]; return $this->asJson($res); } public function actionStoreCopyList() { $from_store_id = input_params('from_store_id', 0); $to_store_id = input_params('to_store_id', 0); $type = input_params('type', ''); $query = StoreCopy::find()->where(['is_delete' => 0])->orderBy('id desc'); $from_store_id && $query->andWhere(['from_store_id' => $from_store_id]); $to_store_id && $query->andWhere(['to_store_id' => $to_store_id]); $type && $query->andWhere(['like', 'type', $type]); $list = pagination_make($query); foreach($list['list'] as &$item){ $item['from_store_name'] = Store::findOne($item['from_store_id'])['name']; $item['to_store_name'] = Store::findOne($item['to_store_id'])['name']; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $list, ]); } public function actionTemplateDefaultInfo() { $default = \app\models\Option::get('store_template_default', 0, 'saas', null)['value']; if($default){ $default = json_decode($default, true); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'default' => $default, ]); } public function actionTemplateDefaultSave() { $id = input_params('id', 0); $type = input_params('type', ['home']); $default = [ 'store_id' => $id, 'type' => $type, ]; \app\models\Option::set('store_template_default', json_encode($default), 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => 'success', ]); } public function actionTemplateStatus() { $id = input_params('id', 0); if(strstr($id, ',')){ $id = explode(',', $id); } $status = input_params('status', 0); StoreTemplate::updateAll(['status' => $status], ['id'=>$id]); return $this->asJson([ 'code' => 0, 'msg' => 'success', ]); } public function actionTemplateDel() { $id = input_params('id', 0); $model = StoreTemplate::findOne($id); $model->is_delete = 1; $model->save(); return $this->asJson([ 'code' => 0, 'msg' => 'success', ]); } public function actionTemplateAdd() { $name = input_params('name', ''); $desc = input_params('desc', ''); $home_pic = input_params('home_pic', '[]'); $center_pic = input_params('center_pic', '[]'); $category_id = input_params('category_id', 0); $store_id = input_params('from_store_id', 0); $model = new StoreTemplate(); $model->name = $name; $model->desc = $desc; $model->home_pic = json_encode($home_pic); $model->center_pic = json_encode($center_pic); $model->category_id = $category_id; $model->store_id = $store_id; $model->save(); return $this->asJson([ 'code' => 0, 'msg' => 'success', ]); } public function actionTemplateList() { $status = input_params('status', -1); $name = input_params('name', ''); $category_id = input_params('category_id', 0); $cond = ['is_delete' => 0]; // $name && $cond[] = ['like', 'name', $name]; $status >= 0 && $cond['status'] = $status; $category_id && $cond['category_id'] = $category_id; $query = StoreTemplate::find()->where($cond); $name && $query->andWhere(['like', 'name', $name]); $pagination = pagination_make($query); $list = $pagination['list']; foreach($list as &$item){ $item['cat_name'] = '-'; if ($item['category_id'] > 0) { $cat = SaasCategory::findOne($item['category_id']); if ($cat) { $item['cat_name'] = $cat->name; } } $item['home_pic'] = json_decode($item['home_pic'], true); $item['center_pic'] = json_decode($item['center_pic'], true); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list, 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'], ], ]); } /** * 获取二维码 */ public function actionGetQr() { $store_id = input_params('id', 0); $scene = "store:{$store_id}"; try{ $res = \app\utils\ShareQrcode::wxQrcode('pages/home/home', $scene); }catch(\Exception $e){ return $this->asJson([ 'code' => 1, 'msg' => '请检查是否已添加小程序', 'e' => $e, ]); } if (isset($res['code']) && $res['code'] == 1) { return $this->asJson([ 'code' => 1, 'msg' => $res['response']['errmsg'], ]); } return $this->asJson([ 'code' => 0, 'data' => $res['url_path'] ]); } public function actionGetKefuInfo() { $store = Store::findOne(get_store_id()); if (!$store) { return $this->asJson([ 'code' => 1, 'msg' => '数据不存在', ]); } $kefu_auto_reply_img = Option::get('kefu_auto_reply_img', $store->id, 'store', '')['value']; $kefu_auto_reply_text = Option::get('kefu_auto_reply_text', $store->id, 'store', '')['value']; $is_show_kefu_download = Option::get('is_show_kefu_download', 0, 'saas', 1)['value']; return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data'=> [ 'kefu_id' => $store->kefu_id ?: '', 'kefu_auto_reply_img' => $kefu_auto_reply_img, 'kefu_auto_reply_text' => $kefu_auto_reply_text, 'is_show_kefu_download' => intval($is_show_kefu_download) ] ]); } public function actionSetKefuInfo() { $kefu_id = \post_params('kefu_id', ''); $kefu_auto_reply_img = \post_params('kefu_auto_reply_img', ''); $kefu_auto_reply_text = \post_params('kefu_auto_reply_text', ''); $store = Store::findOne(get_store_id()); if (!$store) { return $this->asJson([ 'code' => 1, 'msg' => '数据不存在', ]); } Option::set('kefu_auto_reply_img', $kefu_auto_reply_img, $store->id, 'store'); Option::set('kefu_auto_reply_text', $kefu_auto_reply_text, $store->id, 'store'); if (!empty($kefu_id)) { if (!preg_match('/^1[3456789]\d{9}$/i', $kefu_id)) { return $this->asJson([ 'code' => 1, 'msg' => '客服手机号格式错误', ]); } $url = Kefu::API_HOST; $host = \str_replace(['http://', 'https://'], '', \Yii::$app->request->hostInfo); $res = http_post($url . '/api/regKefu', [ 'form_params' => [ 'token' => \Yii::$app->getKefuApiToken(), 'host' => $host, 'mobile' => $kefu_id, 'kefu_auto_reply_img' => $kefu_auto_reply_img, 'kefu_auto_reply_text' => $kefu_auto_reply_text, ] ]); if ($res->getStatusCode() != 200) { return $this->asJson([ 'code' => 1, 'msg' => '请求出错!', ]); } $content = json_decode((string)$res->getBody(), true); if ($content['code'] == 0) { $store->kefu_id = $kefu_id; $store->save(); } } else { $store->kefu_id = ''; $store->save(); $content = [ 'code' => 0, 'msg' => '保存成功', ]; } return $this->asJson($content); } //清除数据可选项 public function actionDelShareHolderOption() { $array = [ [ 'title' => '用户', 'key' => 'user', 'is_checked' => 1, 'is_disabled' => 1 ], [ 'title' => '订单', 'key' => 'order', 'is_checked' => 1, 'is_disabled' => 1 ], [ 'title' => '链动2+1', 'key' => 'shareHolder', 'is_checked' => 1, 'is_disabled' => 0 ], [ 'title' => '全域分佣', 'key' => 'report', 'is_checked' => 0, 'is_disabled' => 0 ], [ 'title' => '37拼购', 'key' => 'shareGroup', 'is_checked' => 0, 'is_disabled' => 0 ], [ 'title' => '团队极差分红', 'key' => 'teamBonus', 'is_checked' => 0, 'is_disabled' => 0 ], [ 'title' => '团队业绩分红', 'key' => 'teamGrades', 'is_checked' => 0, 'is_disabled' => 0 ], [ 'title' => '超级卖货', 'key' => 'superSales', 'is_checked' => 0, 'is_disabled' => 0 ], [ 'title' => '增值积分', 'key' => 'integralAppreciation', 'is_checked' => 0, 'is_disabled' => 0 ], [ 'title' => '视频号爆单', 'key' => 'videoShop', 'is_checked' => 0, 'is_disabled' => 0 ], [ 'title' => '排队免单', 'key' => 'freeQueue', 'is_checked' => 0, 'is_disabled' => 0 ], ]; return $this->asJson([ 'code' => 0, 'msg' => '', 'data' => [ 'key_list' => $array ] ]) ; } //删除链动以及其他测试数据 public function actionDelShareHolderTestInfo() { try { $safe_code = post_params('safe_code'); $captcha = post_params('captcha'); $del_key = post_params('del_key'); $store = Store::findOne(get_store_id()); if (empty($safe_code) && empty($safe_code)) { throw new \Exception("安全码和验证码二选一"); } if (!empty($captcha)) { $form = new LoginForm(); $form->store_id = get_store_id(); $form->phone = $store->contact_tel; $form->verify_code = $captcha; $verifySmsCode = $form->verifySmsCode(LoginForm::TYPE_VERIFY_CODE_CLEAR); if ($verifySmsCode['code'] != 0) { throw new \Exception($verifySmsCode['msg']); } } if (!empty($safe_code)) { if ($safe_code !== "@TianXin100We10Cn") { throw new \Exception("安全码错误"); } } $user = User::find()->where(['store_id' => get_store_id()])->select('id, binding')->asArray()->all(); $user_id = array_column($user, 'id'); $user_mobile = array_column($user, 'binding'); $del_key = $del_key ?: []; $order_id = Order::find()->where(['store_id' => get_store_id()])->select('id')->column(); Order::deleteAll(['store_id' => get_store_id()]); OrderDetail::deleteAll(['order_id' => $order_id]); OrderRefund::deleteAll(['store_id' => get_store_id()]); OrderComment::deleteAll(['store_id' => get_store_id()]); // SaasUser::deleteAll(); User::deleteAll(['store_id' => get_store_id()]); SaasUser::updateAll(['access_token' => ''], ['mobile' => $user_mobile]); UserTreePath::deleteAll(["OR", ['parent_id' => $user_id], ['child_id' => $user_id]]); OldUserTreePath::deleteAll(["OR", ['parent_id' => $user_id], ['child_id' => $user_id]]); ShareDetail::deleteAll(['store_id' => get_store_id()]); ShareHolder::deleteAll(['store_id' => get_store_id()]); ShareHolderFrostLog::deleteAll(["OR", ['parent_user_id' => $user_id], ['child_user_id' => $user_id]]); ShareHolderOutLog::deleteAll(["OR", ['parent_user_id' => $user_id], ['child_user_id' => $user_id]]); BonusPoolLevel::deleteAll(['store_id' => get_store_id()]); ShareHolderLevelLog::deleteAll(['store_id' => get_store_id()]); ShareHolderParentOutLog::deleteAll(['store_id' => get_store_id()]); Cash::deleteAll(['store_id' => get_store_id()]); AccountLog::deleteAll(['store_id' => get_store_id()]); \app\plugins\scanCodePay\models\Order::deleteAll(['store_id' => get_store_id()]); Share::deleteAll(['store_id' => get_store_id()]); UserShareMoney::deleteAll(['store_id' => get_store_id()]); //拼团 // $ptActivityOrderId = PtActivityOrder::find()->where(['store_id' => get_store_id()])->select('id')->column(); // PtActivityOrder::deleteAll(['store_id' => get_store_id()]); // PtActivityOrderDetail::deleteAll(['order_id' => $ptActivityOrderId]); //砍价 // ActivityCutPriceLog::deleteAll(['store_id' => get_store_id()]); // ActivityCutPriceOrder::deleteAll(['store_id' => get_store_id()]); //消费全返 // ActivityOrderRebateSelfOrder::deleteAll(['store_id' => get_store_id()]); // ActivityOrderRebateSelfUser::deleteAll(['store_id' => get_store_id()]); //推N返1 // ActivityRebateOrderNLog::deleteAll(['store_id' => get_store_id()]); //全域分佣 if (in_array('report', $del_key)) { ReportCommitIntegral::deleteAll(['store_id' => get_store_id()]); ReportInfo::deleteAll(['store_id' => get_store_id()]); ReportPool::deleteAll(['store_id' => get_store_id()]); ReportPoolDetail::deleteAll(['store_id' => get_store_id()]); ReportPoolLevel::deleteAll(['store_id' => get_store_id()]); } //团队级差分红 if (in_array('teamBonus', $del_key)) { TeamBonusOrderExt::deleteAll(['store_id' => get_store_id()]); } //37拼购 if (in_array('shareGroup', $del_key)) { $shareGroupMoneyId = ShareGroupMoney::find()->where(['store_id' => get_store_id()])->select('id')->column(); ShareGroupMoney::deleteAll(['store_id' => get_store_id()]); ShareGroupMoneySub::deleteAll(['share_money_id' => $shareGroupMoneyId]); ShareGroupSupportLog::deleteAll(['store_id' => get_store_id()]); ShareGroupPurchaseParentLog::deleteAll(['store_id' => get_store_id()]); ShareGroupPurchaseUser::deleteAll(['store_id' => get_store_id()]); } //超级卖货系统 if (in_array('superSales', $del_key)) { $superSalesId = SuperSales::find()->where(['store_id' => get_store_id()])->select('id')->column(); SuperSales::deleteAll(['store_id' => get_store_id()]); SuperSalesSub::deleteAll(['sales_id' => $superSalesId]); SuperSalesUser::deleteAll(['store_id' => get_store_id()]); SuperSalesMoney::deleteAll(['store_id' => get_store_id()]); SuperSalesRepeatOrder::deleteAll(['store_id' => get_store_id()]); } //团队业绩 if (in_array('teamGrades', $del_key)) { TeamGrades::deleteAll(['store_id' => get_store_id()]); TeamGradesAudit::deleteAll(['store_id' => get_store_id()]); TeamGradesDividendLog::deleteAll(['store_id' => get_store_id()]); $teamGradesPoolId = TeamGradesPool::find()->where(['store_id' => get_store_id()])->select('id')->column(); TeamGradesPool::deleteAll(['store_id' => get_store_id()]); TeamGradesPoolDetail::deleteAll(['pool_id' => $teamGradesPoolId]); TeamGradesPoolDetailExt::deleteAll(['order_id' => $order_id]); } //消费积分增值 if (in_array('integralAppreciation', $del_key)) { IntegralAppreciationCommunity::deleteAll(['store_id' => get_store_id()]); IntegralAppreciationUser::deleteAll(['store_id' => get_store_id()]); IntegralAppreciationCashLog::deleteAll(['user_id' => $user_id]); IntegralAppreciationUserIntegralLog::deleteAll(['order_id' => $order_id]); IntegralAppreciationPool::deleteAll(['store_id' => get_store_id()]); IntegralAppreciationPoolSub::deleteAll(['store_id' => get_store_id()]); } //视频号爆单 if (in_array('videoShop', $del_key)) { PublicRankingTask::deleteAll(['store_id' => get_store_id()]); PublicRankingUser::deleteAll(['store_id' => get_store_id()]); Promoter::deleteAll(['store_id' => get_store_id()]); VideoShopGoodsExt::deleteAll(['store_id' => get_store_id()]); VideoShopOrderExt::deleteAll(['store_id' => get_store_id()]); VideoShopUser::deleteAll(['store_id' => get_store_id()]); VideoShopOrderExtAli::deleteAll(['store_id' => get_store_id()]); VideoShopSharer::deleteAll(['store_id' => get_store_id()]); } //排队免单 if (in_array('freeQueue', $del_key)) { QueueAccountLog::deleteAll(['store_id' => get_store_id()]); QueueLog::deleteAll(['store_id' => get_store_id()]); } return $this->asJson([ 'code' => 0, 'msg' => "操作成功" ]); } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } public function actionSendCode() { $form = new LoginForm(); $store = Store::findOne(get_store_id()); $form->phone = $store->contact_tel; $form->store_id = get_store_id(); return $this->asJson($form->sendCode(LoginForm::TYPE_VERIFY_CODE_CLEAR)); } public function actionTimerTaskCopy() { $autoDownGoods = \Yii::$app->request->hostInfo . '/index.php?r=common/task/auto-off-goods'; $order = \Yii::$app->request->hostInfo . '/index.php?r=common/task/execute'; $queue = ''; $user = get_current_user(); $www_path = \Yii::$app->basePath . '/'; $queue_cli = ''; \ob_start(); \phpinfo(INFO_GENERAL); $phpinfo = \ob_get_contents(); ob_end_clean(); \preg_match("/--prefix=(.*)' '/U", $phpinfo, $matches); if (isset($matches[1])) { $queue_cli = $matches[1] . '/bin/php yii queue/listen'; $queue = 'su -c "' . $matches[1] . '/bin/php ' . \Yii::$app->basePath . '/yii queue/run' . '" -s /bin/sh ' . $user; } else { $queue = '获取php cli路径失败, 请手动获取'; } return $this->asJson([ 'code' => 0, 'data' => [ 'autoDownGoods' => $autoDownGoods, 'order' => $order, 'queue' => $queue, 'queue_cli' => $queue_cli, 'www_path' => $www_path, ], 'msg' => 'success' ]); } public function actionSetAppParams() { try { if (\Yii::$app->request->isPost) { $key = [ OptionSetting::APP_STORE_ANDROID, OptionSetting::APP_STORE_ANDROID_VERSION, OptionSetting::STORE_APP_LOGO, OptionSetting::STORE_APP_BG, OptionSetting::APP_STORE_IOS, OptionSetting::APP_IS_OPEN_MAP, OptionSetting::MAP_APP_CODE, ]; $params = post_params(); $value = [ $params['app_store_android'], $params['app_store_android_version'], $params['store_app_logo'], $params['store_app_bg'], $params['app_store_ios'], $params['app_is_open_map'], $params['map_app_code'], ]; Option::set($key, $value, get_store_id(), 'app'); return $this->asJson([ 'code' => 0, 'msg' => '' ]); } else { $keys = [ OptionSetting::APP_STORE_ANDROID, OptionSetting::APP_STORE_ANDROID_VERSION, OptionSetting::STORE_APP_LOGO, OptionSetting::STORE_APP_BG, OptionSetting::APP_STORE_IOS, OptionSetting::APP_IS_OPEN_MAP, OptionSetting::MAP_APP_CODE, ]; $data = Option::get($keys, get_store_id(), 'app'); if (empty($data)) { $data = [ OptionSetting::APP_STORE_ANDROID => '', OptionSetting::APP_STORE_ANDROID_VERSION => '', OptionSetting::STORE_APP_LOGO => '', OptionSetting::STORE_APP_BG => '', OptionSetting::APP_STORE_IOS => '', OptionSetting::APP_IS_OPEN_MAP => 2, OptionSetting::MAP_APP_CODE => '', ]; } else { $arr = []; foreach ($data as $value) { $index = array_search($value['name'], $keys); unset($keys[$index]); $arr[$value['name']] = $value['value']; } foreach ($keys as $key) { $arr[$key] = ''; } $data = $arr; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } //设置商城版权信息 public function actionSetCopyright() { try { $store_id = input_params('id') ?? get_store_id(); if (\Yii::$app->request->isPost) { $copyright_params = []; $copyright_params['type'] = post_params('type') ?? 0; $copyright_params['mini_url'] = post_params('mini_url') ?? ''; $copyright_params['mobile'] = post_params('mobile') ?? ''; $copyright_params['logo'] = post_params('logo') ?? ''; $copyright_params['copyright'] = post_params('copyright') ?? ''; Option::set('copyright', json_encode($copyright_params), $store_id, 'store'); return $this->asJson([ 'code' => 0, 'msg' => '操作成功' ]); } else { $copyright = Option::get('copyright', $store_id, 'store', '')['value']; $store_admin = Admin::findOne(['type' => 'store', 'type_id' => $store_id, 'is_delete' => 0]); $store = Store::findOne($store_id); $copyright = json_decode($copyright, true) ?: [ 'type' => 1, 'mini_url' => [ 'name' => '商城首页', 'link' => '/pages/home/home', 'open_type' => "switchtab", 'params' => [] ], 'mobile' => $store_admin->mobile ?? '', 'logo' => $store->logo ?: (Option::get('logo', $store_id, 'store')['value'] ?: Option::get('web_log', $store_id, 'web')['value']), 'copyright' => $store->name ]; $copyright['type'] = intval($copyright['type']); return $this->asJson([ 'code' => 0, 'msg' => '获取成功', 'data' => $copyright ]); } } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } //设置商城联盟积分比例 public function actionSetStoreIntegral() { try { $store_id = input_params('id') ?? get_store_id(); if (\Yii::$app->request->isPost) { $face_pay_integral_profit = post_params('face_pay_integral_profit', 0); $online_pay_integral_profit = post_params('online_pay_integral_profit', 0); Option::set([ 'face_pay_integral_profit', 'online_pay_integral_profit' ], [ $face_pay_integral_profit, $online_pay_integral_profit ], $store_id, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功' ]); } else { $face_pay_integral_profit = Option::get('face_pay_integral_profit', $store_id, 'saas', 0)['value']; $online_pay_integral_profit = Option::get('online_pay_integral_profit', $store_id, 'saas', 0)['value']; return $this->asJson([ 'code' => 0, 'msg' => '获取成功', 'data' => [ 'face_pay_integral_profit' => $face_pay_integral_profit, 'online_pay_integral_profit' => $online_pay_integral_profit, ] ]); } } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } // 当面付支付后跳转设置 public function actionSettingFacePayPath() { $store_id = get_store_id(); if (\Yii::$app->request->isPost) { $face_pay_path = post_params('face_pay_path', ''); $face_pay_path = json_encode($face_pay_path, JSON_UNESCAPED_UNICODE); Option::set('face_pay_path', $face_pay_path, 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } $data = [ 'face_pay_path' => Option::get('face_pay_path', 0, 'saas', '')['value'] ]; $data['face_pay_path'] = json_decode($data['face_pay_path'], true) ?: null; return $this->asJson([ 'code' => 0, 'data' => $data, 'msg' => 'success', ]); } //联盟券列表 public function actionStoreLeagueLog() { // 区分平台或者商城 $store_id = get_params('store_id'); //条件 $user_name = get_params('user_name'); $mobile = get_params('mobile'); $start_time = get_params('start_time'); $end_time = get_params('end_time'); // $query = SaaSLeaguePriceLog::find()->alias('lpl') ->where(['lpl.role' => SaaSLeaguePriceLog::ROLE_USER, 'lpl.is_delete' => 0]) ->andWhere(['>', 'lpl.league_price', 0]); if ($store_id) { $query->andWhere(['lpl.store_id' => $store_id]); } if ($user_name) { $query->andWhere(['LIKE', 'su.name', $user_name]); } if ($mobile) { $query->andWhere(['LIKE', 'su.mobile', $mobile]); } if ($start_time) { $start_time = strtotime($start_time); $query->andWhere(['>=', 'lpl.addtime', $start_time]); } if ($end_time) { $end_time = strtotime($end_time); $query->andWhere(['<=', 'lpl.addtime', $end_time]); } $query->leftJoin(['su' => SaasUser::tableName()], 'su.id = lpl.saas_user_id'); $query->select('lpl.id, lpl.saas_user_id, lpl.type, lpl.order_id, lpl.send_or_take_type, lpl.store_id, lpl.after, lpl.before, lpl.league_price, lpl.addtime, su.name user_name, su.mobile user_mobile, su.avatar user_avatar') ->orderBy('lpl.id desc'); $pagination = pagination_make($query); foreach ($pagination['list'] as &$item) { $item['addtime'] = date("Y-m-d H:i:s", $item['addtime']); $item['send_or_take_type'] = (int)$item['send_or_take_type']; $item['type'] = (int)$item['type']; $item['type_name'] = SaaSLeaguePriceLog::getTypeStr($item['type']); $item['order_no'] = ''; if ($item['order_id']) { if (in_array($item['type'], [ SaaSLeaguePriceLog::TYPE_ORDER_REBATE,//下单返利 SaaSLeaguePriceLog::TYPE_CANCEL,//订单取消退回 SaaSLeaguePriceLog::TYPE_DEDUCTION,//下单抵扣 ])) { $order = Order::findOne($item['order_id']); } if ($item['type'] === SaaSLeaguePriceLog::TYPE_LEAGUE_RECHARGE) {//联盟券 $order = RechargeReOrder::findOne($item['order_id']); } if (in_array($item['type'], [ SaaSLeaguePriceLog::TYPE_WITHDRAW, SaaSLeaguePriceLog::TYPE_WITHDRAW_REJECT, ])) {//联盟券提现 $order = Cash::findOne($item['order_id']); } if ($item['type'] === SaaSLeaguePriceLog::TYPE_FACE_PAY_ORDER) {//当面付 $order = \app\plugins\scanCodePay\models\Order::findOne($item['order_id']); } if (isset($order)) { $item['order_no'] = $order->order_no ?: ''; } } $store = Store::findOne($item['store_id']); $item['store_name'] = $store ? $store->name : ''; } $league_price_query = Store::find()->where(['is_delete' => 0]); if ($store_id) { $league_price_query->andWhere(['id' => $store_id]); } $league_price = $league_price_query->select('league_price')->sum('league_price') ?: 0; return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $pagination['list'], 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'], 'league_price' => $league_price ], ]); } public function actionIsPlatformTransfers() { $id = get_params('id'); $isPlatformTransfers = get_params('is_platform_transfers'); try { $transaction = \Yii::$app->db->beginTransaction(); $store = Store::findOne($id); if (!$store) { throw new \Exception('店铺不存在'); } $store->is_platform_transfers = $isPlatformTransfers; if (!$store->save()) { if ($store->hasErrors()) { throw new \Exception('Validation failed: ' . implode(', ', $store->getFirstErrors())); } else { throw new \Exception('Failed to save the changes.'); } } $transaction->commit(); return $this->asJson([ 'code' => 0, 'msg' => 'Success', 'data' => $store, ]); } catch (\Exception $e) { if (isset($transaction) && $transaction->isActive) { $transaction->rollBack(); } return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage(), 'data' => [] ]); } } public function actionStoreRecharge() { $data = get_params(); $rechargeType = $data['recharge_type']; $id = $data['id']; $money = $data['money']; $store = Store::findOne($id); $before = $store->store_balance; $after = 0; if ($rechargeType == 1) { $store->total_store_quota += $money; $store->store_balance += $money; $store->price += $money; $store->total_price += $money; $after = $store->store_balance; $result = StoreMoneyLog::saveLog($id, StoreMoneyLog::LOG_TYPE_INCOME, StoreMoneyLog::TYPE_STORE, $money, "后台充值: {$money}", $before, $after); } else { if ($store->store_balance >= $money) { $store->store_balance -= $money; $store->total_price -= $money; $store->price -= $money; $after = $store->store_balance; $result = StoreMoneyLog::saveLog($id, StoreMoneyLog::LOG_TYPE_EXPEND, StoreMoneyLog::TYPE_STORE, $money, "后台扣除: {$money}", $before, $after); } else { return $this->asJson([ 'code' => 1, 'msg' => 'error', 'data' => [], ]); } } if ($result !== true) { return $this->asJson([ 'code' => 1, 'msg' => 'error', 'data' => [], ]); } if (!$store->save()) { return $this->asJson([ 'code' => 1, 'msg' => 'error', 'data' => [], ]); } return $this->asJson([ 'code' => 0, 'msg' => 'Success', 'data' => $store, ]); } public function actionStoreMoneyHistory() { $id = get_params('id'); $data = StoreMoneyLog::find()->alias('l') ->leftJoin(['s' => Store::tableName()], 's.id = l.store_id') ->select('l.*, s.name store_name') ->where(['l.store_id' => $id])->orderBy('l.id desc')->asArray()->all(); foreach ($data as &$value) { $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']); switch ($value['type']) { case 1: $value['type'] = '分销提现'; break; case 2: $value['type'] = '股东分红提现'; break; case 3: $value['type'] = '门店提现'; break; case 4: $value['type'] = '2+1提现'; break; default: $value['type'] = '后台操作'; break; } } return $this->asJson([ 'code' => 0, 'msg' => 'Success', 'data' => $data, ]); } //获取商城微信小程序码 public function actionGetWechatQrcode() { try { $store_id = get_params('store_id'); $store = Store::findOne($store_id); $is_platform = 0; if (intval($store->business_model) !== 1) { $is_platform = 1; } $app = WechatMini::getWechatConfig($store_id, 0, 0, $is_platform); if (!$app) { throw new \Exception('没有对应的小程序'); } $page = "pages/home/home"; $scene = "store:{$store_id}"; if ($store->business_model == 2) { //平台运营 $page = 'pages/shop/shopIndex'; $scene = "store_id:{$store_id}"; } elseif ($store->business_model == 3) { //当面付 $page = 'face-pay/face-pay/payOut'; $scene = "store_id:{$store_id}"; } elseif ($store->business_model == 4) { //点餐 $page = 'alipay-order/orderMeal/orderMeal'; $scene = "md_id:-1,store_id:{$store_id}"; } $response = $app->app_code->getUnlimit($scene, [ 'page' => $page ]); $filename = md5(time() . 'pages_home') . '.jpg'; $filePath = \Yii::$app->basePath . '/runtime/image/wx_qrcode'; if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) { $resfilename = $response->saveAs($filePath, $filename); if (!empty($resfilename)) { $filePath = 'https://' . str_replace(\Yii::$app->basePath, \Yii::$app->request->hostName, $filePath . '/' . $filename); return $this->asJson([ 'code' => 0, 'msg' => "获取成功", 'data' => $filePath ]); } else { throw new \Exception("数据错误"); } } else { throw new \Exception("数据错误"); } } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } }