TimestampBehavior::class, 'value' => time() ] ]; } /** * @inheritdoc */ public function rules() { return [ [['rank', 'per_spend', 'self_rebate_value'], 'number'], [['id', 'admin_id', 'salesman_id', 'is_delete', 'is_alliance', 'created_at', 'updated_at', 'parent_id', 'category_id', 'province_id', 'city_id', 'district_id', 'sales', 'delivery_type', 'end_time', 'food_pay_type', 'open_status', 'shop_time_type', 'is_time_forbid', 'is_set_distance', 'store_admin', 'store_share_switch', 'store_share_type', 'business_model', 'self_rebate_switch', 'is_auth_trans', 'is_use_default', 'wechat_delivery_type','is_platform_transfers'], 'integer'], [['delivery_category', 'share_setting', 'douyin_url', 'recommend_keyword', 'app_auth_token', 'coordinate', 'address', 'shop_id', 'name', 'logo','store_front_photo', 'tags', 'contact_tel', 'user_name', 'wechat_msg_token', 'md_banner', 'md_agreement', 'food_payment', 's_time', 'e_time', 'auth', 'device_name', 'kefu_id', 'store_number', 'cusid', 'yunst_user_id'], 'string'], [['transfer_profit', 'open_price', 'renew_price', 'profit', 'distance', 'rate', 'store_share_value', 'latitude', 'longitude', 'price', 'total_price', 'scan_transfer_profit', 'ratio', 'food_transfer_profit', 'cashier_transfer_profit','small_model_proportion'], 'double'], [['created_at', 'update_at', 'info','store_url_info'], 'safe'] ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'admin_id' => '管理员ID', 'created_at' => '创建时间', 'updated_at' => '更新时间', 'share_setting' => 'saas分销配置', 'transfer_profit' => '商城让利比例', 'scan_transfer_profit' => '当面付让利比例', 'is_alliance' => '是否加入联盟', // 0=未加入, 1=加入, 2=待审核 'recommend_keyword' => '店铺推荐关键词', 'is_delete' => '是否已删除', 'douyin_url' => '抖口令', 'parent_id' => '父级ID', 'coordinate' => '坐标', 'address' => '商城地址', 'shop_id' => '蚂蚁门店id', 'app_auth_token' => '授权token', 'category_id' => '分类id', 'info' => '类目筛选信息', 'name' => '商城名称', 'logo' => '商城logo', 'province_id' => '省id', 'city_id' => '市id', 'district_id' => '区域id', 'sales' => '销量', 'rank' => '评分', 'per_spend' => '人均花费', 'tags' => '标签', 'wechat_msg_token' => '微信推送消息token', 'open_price'=>"开铺金额", 'renew_price'=>"续费金额", 'end_time'=>"有效期", 'profit'=>"分佣金额", 'store_admin' => '商城管理员saas_user_id', 'rate' => '销售溢价比', 'store_share_switch' => '店铺间分销开关', 'store_share_type' => '店铺间分销佣金类型', 'store_share_value' => '店铺间分销值', 'business_model' => '运营模式', 'auth' => '商盟对店铺的权限控制', 'device_name' => '语音播报设备名称', 'is_auth_trans' => '是否自动转单', 'is_use_default' => '是否使用默认费用设置', 'kefu_id' => '客服id', 'price' => '店铺可提现金额', 'total_price' => '店铺累计金额', 'league_price' => '店铺联盟券金额', 'wechat_delivery_type' => '微信配送方式0即时配送(旧) 1同城配送', 'store_number' => '商城编号', 'cusid' => '进件商户号', 'ratio' => '通联签约抽佣比例', 'yunst_user_id' => '通联生成的会员UID', ]; } public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); // 云仓溢价比例修改后,同步云仓商品价格 if (isset($changedAttributes['rate']) && $changedAttributes['rate'] != $this->rate) { $job = new \app\jobs\SyncCloudGoodsPriceJob(); $job->store_id = $this->id; \queue_push($job); } } public function beforeSave($insert) { if (parent::beforeSave($insert)) { if (\Yii::$app->prod_is_shangmeng()) { // 商盟版本没有独立运营, 如果传的是1,改成默认2 if ($this->business_model == 1 || empty($this->business_model)) { $this->business_model = 2; } } if($insert){ $count = 0; if($this->salesman_id > 0){ $salesman = Salesman::findOne($this->salesman_id); $currentAdmin = Admin::findOne($salesman->admin_id); }else{ $currentAdmin = Admin::findOne($this->admin_id); } if($currentAdmin && $currentAdmin->type == Admin::ADMIN_TYPE_BD_AGENT){ $count = Store::find()->where(['is_delete' => 0]) ->andWhere([ 'or', ['admin_id' => $currentAdmin->id], ['salesman_id' => Salesman::find()->where(['admin_id' => $currentAdmin->id, 'is_delete' => 0])->select('id')] ])->count(); $canStoreCount = $currentAdmin->max_app_count - $count; if($canStoreCount <= 0){ \Yii::error([__METHOD__, $this->admin_id, $currentAdmin->max_app_count, $count, $this->attributes, '商城数量超过限制']); $this->addError('max_app_count', '操作失败,商城数量超过限制'. $count . '/' . $currentAdmin->max_app_count); return false; } } } return true; } return false; } public function getCategory(){ return $this->hasOne(SaasCategory::className(),['id'=>'category_id']); } public function getOrder(){ return $this->hasMany(Order::className(),['store_id'=>'id']); } public function getReorder(){ return $this->hasMany(StoreReOrder::className(),['store_id'=>'id']); } public function getAdmin(){ return $this->hasOne(Admin::className(),['id'=>'admin_id']); } public static function nameList() { return self::find()->andWhere(['is_delete' => 0])->asArray()->select('id,name,salesman_id')->all(); } // 是否进件 // yunst是否是通联支付 public static function hasIncoming($store_id, $platform = 'wechat') { if (($platform == 'alipay') || is_alipay_platform()) { $data = StoreAliMini::findOne(['store_id' => $store_id, 'is_cancel' => 0, 'batch_status' => [2, 6]]); if (!$data) { return false; } return true; } elseif (($platform == 'wechat' || $platform == 'yunst') || is_wechat_platform()) { $data = MerchantInfo::find()->where([ 'bind_store_id' => $store_id, 'status' => 3, 'is_use' => 1, 'is_yunst' => intval($platform == 'yunst'), 'is_delete' => 0 ])->one(); if (!$data) { return false; } if (empty($data->sub_mch_id)) { return false; } return true; } } public static function isStoreCurrency($store_id) { $saleman_id = Store::find()->where(['id'=>$store_id,'is_delete'=>0])->select('salesman_id')->scalar(); if (!$saleman_id) return false; $store_id = Salesman::find()->alias('s')->leftJoin(['a'=>Admin::tableName()],'s.admin_id = a.id') ->where(['s.id'=>$store_id,'s.is_delete'=>0])->select('a.store_id')->scalar(); $coin = \Yii::$app->db->createCommand("SELECT money,user_percent FROM cyy_user_wallet_coin where store_id= :store_id and is_status=1 and shop_status = 1") ->bindValues([ ':store_id' => $store_id, ])->queryOne(); if (!$coin || $coin['money'] <= 0) return false; $setting = Option::getShareDefaultSetting($store_id); if (!isset($setting['currceny_percent_scan']) || $setting['currceny_percent_scan']<=0) return false; $data['percent'] = ($setting['currceny_percent_scan'] * $coin['user_percent'])/100; $data['money'] = $coin['money']; return $data; } public static function is_red_package($store_id) { $coin = Option::getShareSaleSetting($store_id); $setting = Option::getShareDefaultSetting($store_id); if (!isset($setting['scan_qr_code_percent']) || $setting['scan_qr_code_percent']<=0) return false; if (!isset($coin['string_code_store_red_packet']) || $coin['string_code_store_red_packet']<=0) return false; $data['percent'] = ($setting['scan_qr_code_percent'] * $coin['string_code_store_red_packet'])/100; return $data; } // 店铺累计金额 public static function getTotalMoney($store) { return $store->total_price; } // 店铺金额 public static function getMoney($store) { return $store->price; } // 店铺减少金额 public static function subMoney($store, $price, $desc = '账户提现',$cash_id=0) { $t = \Yii::$app->db->beginTransaction(); try { $before = $store->price; $store->price -= $price; if (!$store->save()) { throw new \Exception('商城金额减少失败'); } $log = new StoreAccountLog(); $log->store_id = $store->id; $log->price = $price; $log->desc = $desc; $log->before = $before; $log->after = $store->price; $log->type = 2; $log->time = time(); $log->order_id = $cash_id; if (!$log->save()) { throw new \Exception('商城金额日志记录失败'); } $t->commit(); } catch (\Exception $e) { $t->rollBack(); return false; } return true; } // 店铺增加金额 public static function addMoney($store, $price, $desc = '用户下单', $order_id = 0, $user_id = 0) { $t = \Yii::$app->db->beginTransaction(); try { if($order_id){ $StoreAccountLog = StoreAccountLog::findOne(['order_id' => $order_id, 'user_id' => $user_id, 'store_id' => $store->id, 'type' => 1]); if($StoreAccountLog){ throw new \Exception('此订单已存在商城金额增加记录'); } } $before = $store->price; $store->price += $price; $store->total_price += $price; if (!$store->save()) { throw new \Exception('商城金额增加失败'); } $log = new StoreAccountLog(); $log->store_id = $store->id; $log->order_id = $order_id; $log->user_id = $user_id; $log->price = $price; $log->desc = $desc; $log->before = $before; $log->after = $store->price; $log->type = 1; $log->time = time(); if (!$log->save()) { throw new \Exception('商城金额日志记录失败'); } $t->commit(); } catch (\Exception $e) { \Yii::error($e); $t->rollBack(); return false; } return true; } //小程序是否开启审核 public static function mpAudit($store_id) { $audit_status = Option::get('is_shenhe', $store_id, 'wechat', 0)['value']; $is_ali_shenhe = Option::get('is_ali_shenhe', $store_id, 'wechat', 0)['value']; $is_component_ali_shenhe = Option::get('is_component_ali_shenhe', $store_id, 'wechat', 0)['value']; if ((int)$is_ali_shenhe === 1 && is_alipay_platform()) { $audit_status = 1; } if ((int)$audit_status === 1 && (int)$is_ali_shenhe === 0 && is_alipay_platform()) { $audit_status = 0; } if ((int)$is_ali_shenhe === 1 && (int)$is_component_ali_shenhe === 0) { $is_ali_shenhe = 0; } elseif ((int)$is_ali_shenhe === 1 && (int)$is_component_ali_shenhe === 1 && is_alipay_platform()) { $is_ali_shenhe = 1; $audit_status = 1; } if (\Yii::$app->prod_is_dandianpu() && is_single_store()) { if (is_wechat_platform()) { $audit_status = Option::get('one_store_is_shenhe', 0, 'saas', 0)['value']; } if (is_alipay_platform()) { $one_store_alipay_config = json_decode(Option::get('one_store_alipay_config', 0, 'saas', '')['value'], true); $audit_status = !empty($one_store_alipay_config['one_store_is_shenhe']) ? $one_store_alipay_config['one_store_is_shenhe'] : 0; } } $wechat_login_toggle_article = Option::get('wechat_login_toggle_article', $store_id, 'wechat', 0)['value']; //审核页面文章 $article = null; if ($wechat_login_toggle_article) { $aboutArticle = AboutArticle::findOne($wechat_login_toggle_article); $article = [ 'name' => $aboutArticle->name ?? '', 'desc' => $aboutArticle->desc ?? '' ]; } // 根据版本判断是否开启审核,低版本的不开启,最新版本开启 if (\client_version() < \cyy_version()) { $audit_status = 0; $is_ali_shenhe = 0; } // 是否允许切换门店 $mdSetting = MdSetting::findOne(['store_id' => $store_id]); $changeShop = $mdSetting->change_shop ?? 1; return [ 'status' => $audit_status, 'is_ali_shenhe' => intval($is_ali_shenhe), 'article' => $article, 'change_shop' => $changeShop ]; } // 店铺结算减少pv奖励金额 public static function subStoreMoney($store, $price, $desc = '扣pv奖励金额', $order_id = 0, $user_id = 0 ,$huifuId = 0) { $t = \Yii::$app->db->beginTransaction(); try { $before = $store->price; $store->price -= $price; if (!$store->save()) { throw new \Exception('店铺金额减少失败'); } $log = new StoreAccountLog(); $log->store_id = $store->id; $log->order_id = $order_id; $log->user_id = $user_id; $log->price = $price; $log->desc = $desc; $log->before = $before; $log->after = $store->price; $log->type = 2; $log->time = time(); if (!$log->save()) { throw new \Exception('商城金额日志记录失败'); } $t->commit(); return $log->id; } catch (\Exception $e) { \Yii::error($e); $t->rollBack(); return false; } } }