255], [['shop_mobile'], 'string', 'max' => 11], [['intra_city_distribution','customer_service'], 'string', 'max' => 500], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'user_id' => '绑定会员id', 'shop_owner' => '店长姓名', 'shop_mobile' => '店长手机号', 'store_name' => '门店名称', 'c_id' => '门店分类', 'store_desc' => '门店简介', 'logo_img' => '门店logo', 'license_img' => '营业执照', 'province_id' => '省', 'city_id' => '市', 'district_id' => '区', 'address' => '详细地址', 'expire_time' => '失效时间,0代表无限期', 'total_money' => '累计收入', 'balance' => '当前余额', 'total_expenses' => '累计支出', 'user_nums' => '会员总数', 'longitude' => '经度', 'latitude' => '维度', 'check_status' => '审核状态:0:待审核;1:已通过;2:未通过', 'check_remark' => '审核备注', 'store_style' => '门店样式 1:样式1;2:样式2', 'commission_authority' => '分佣/营销权限', 'share_title' => '分享标题', 'share_desc' => '分享描述', 'share_pic' => '分享图片', 'freight_type' => '配送设置', 'intra_city_distribution' => '同城配送', 'total_order_money' => '订单总金额', 'total_num' => '总数', 'total_settled_amount' => '已结算总金额', 'unsettled_amount' => '未结算金额', 'sales_volume' => '销量', 'praise' => '评分', 'status' => '状态[0禁用 1启用 -1删除]', 'shop_status' => '门店营业状态,1:正在营业;0:休息中', 'scan_code_bind' => '门店收款码-扫码绑定开关:0:否;1:是', 'created_at' => '创建时间', 'updated_at' => '修改时间', 'customer_service' => '客服设置', ]; } public static function setData(array $params) { try { if (!empty($params['id'])) { $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if (empty($model)) throw new \Exception('门店不存在或已删除'); } else { $model = new self(); $model->loadDefaultValues(); } if (!empty($params['freight_type'])) $params['freight_type'] = json_encode($params['freight_type']); if (!empty($params['intra_city_distribution'])) $params['intra_city_distribution'] = json_encode($params['intra_city_distribution']); if (!empty($params['customer_service'])) $params['customer_service'] = json_encode($params['customer_service']); if (!$model->load($params, '') || !$model->save()) { throw new \Exception($model->getErrorMessage()); } return $model; } catch (\Exception $e) { self::$static_error = $e->getMessage() . $e->getLine() . $e->getFile(); return false; } } public static function addStore(array $params) { $transaction = \Yii::$app->db->beginTransaction(); $res = self::setData($params); if (false === $res) { $transaction->rollBack(); return false; } $pwd_str = substr($params['shop_mobile'], -6); $pwd_hash_str = \Yii::$app->security->generatePasswordHash($pwd_str); $admin_info = [ 'username' => $params['shop_mobile'], 'account' => $params['shop_owner'], 'password' => $pwd_hash_str, 'mall_id' => $params['mall_id'], 'admin_type' => 2, 'status' => StatusEnum::ENABLED, 'mch_id' => $res->id, ]; $admin_model = MchAdmin::find() ->where(['mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED, 'username' => $params['shop_mobile']]) ->one(); if (!empty($admin_model)) { $transaction->rollBack(); self::$static_error = '多商户管理员账号已经存在'; return false; } $admin_model = new MchAdmin(); $admin_model->loadDefaultValues(); $admin_model->attributes = $admin_info; $admin_model->updated_at = time(); $admin_model->created_at = time(); $res_ad = $admin_model->save(); if (false === $res_ad) { $transaction->rollBack(); self::$static_error = $admin_model->getErrorMessage(); return false; } $transaction->commit(); return true; } /** * @name: * @msg: 装修页面获取门店列表 * @param {int} $mall_id * @param {array} $params * @return {*} */ public static function getMchListInDiy(int $mall_id, array $params = []) { $wheres[] = ['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'check_status' => MchEnum::CHECK_ADOPT,'shop_status' => 1]; if (!empty($params['store_id'])) { $wheres[] = ['id' => $params['store_id']]; } if (!empty($params['store_name'])) { $wheres[] = ['like', 'store_name', $params['store_name']]; } if (!empty($params['storeowner'])) { $wheres[] = ['like', 'shop_owner', $params['storeowner']]; } $params = [ 'select' => '*,store_name as title,logo_img as img', 'where' => $wheres, 'order' => 'created_at desc', ]; $store_list = self::listPage($params); if (false === $store_list) { return false; } return $store_list; } public static function getGoodListInDiy(int $mall_id, array $params) { $wheres[] = ['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'check_status' => MchEnum::CHECK_ADOPT, 'is_on_sale' => 1]; if (!empty($params['keyword'])) { $wheres[] = ['like', 'goods_name', $params['keyword']]; } $params = [ 'where' => $wheres, 'order' => 'sort asc,created_at desc', 'page' => $params['page'] ?? 1, 'limit' => $params['limit'] ?? 15, ]; $list = Goods::listPage($params); if (false === $list) { return Goods::$static_error; } foreach ($list['list'] as &$lv) { $lv['title'] = $lv['goods_name']; } return $list; } //结算货款 public static function settlementStoreCommission($order_id, $mch_id, $order_no) { $mch = Mch::findOne(['id' => $mch_id]); $store_commission_model = MchCommission::findOne(['order_no' => $order_no, 'is_settlement' => 0,'status'=>StatusEnum::ENABLED]); if ($store_commission_model) { $mch->balance += $store_commission_model->amount_received; $mch->total_settled_amount += $store_commission_model->amount_received; $mch->unsettled_amount -= $store_commission_model->amount_received; if ($mch->unsettled_amount < 0) $mch->unsettled_amount = 0; $res = $mch->save(); if ($res == false) throw new \Exception('多商户订单完成结算货款,更新店铺结算金额失败,order_id:' . $order_id); $store_commission_model->is_settlement = 1; $res = $store_commission_model->save(); if ($res == false) throw new \Exception('多商户订单完成结算货款,更新提成记录失败,order_id:' . $order_id); } } public static function delStore($mall_id,$mch_id){ $mch = Mch::findOne(['id'=>$mch_id,'mall_id'=>$mall_id,'status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]]); if(empty($mch)) throw new \Exception('商户不存在'); if($mch['balance']>0) throw new \Exception('商户余额不为0,请先提现后再删除'); $order = Order::getOne([ ['mch_id'=>$mch_id], ['order_status'=>[OrderStatusEnum::PAY,OrderStatusEnum::SHIPMENTS,OrderStatusEnum::SING]], ['is_feedback'=>[0,2]] ]); if(!empty($order)) throw new \Exception('请等订单完成后再删除'); $mch->status = StatusEnum::DELETE; $res = $mch->save(); if(empty($res)) throw new \Exception('删除失败'); MchAdmin::updateAll(['status'=>StatusEnum::DELETE],['mch_id'=>$mch_id,'mall_id'=>$mall_id]); return true; } }