StoreAdminLogin::class, ] ]; return ArrayHelper::merge(parent::behaviors(), $merge); } //手机端管理员登录 public function actionLogin() { $model = new AdminForm(); $model->attributes = post_params(); $model->validatePassword('password'); if ($model->login()) { try { $admin = $model->getAdmin(); if ($admin->type !== Admin::ADMIN_TYPE_MINI_ADMIN) { throw new \Exception('账户类型错误'); } $store_admin = StoreAdmin::findOne(['id' => $admin->type_id, 'is_delete' => 0, 'status' => 1, 'store_id' => get_store_id()]); if (empty($store_admin)) { throw new \Exception('账户信息错误,或被禁用'); } $token = $this->setToken($store_admin->id); return $this->asJson([ 'code' => 0, 'msg' => '登录成功', 'data' => [ 'Authorization' => $token ] ]); } catch (\Throwable $throwable) { return $this->asJson([ 'code' => 1, 'msg' => $throwable->getMessage(), ]); } } return $this->asJson([ 'code' => 1, 'msg' => $model->getFirstErrors()['password'] ]); } /** * 商品 **/ //管理中心 public function actionStoreInfo(){ $form = new StoreAdminForm(['mch_id' => $this->mch['id']]); $form->wechat = $this->wechat; $res = $form->storeInfo(); return $this->asJson($res); } //店铺数据 public function actionShopData() { $form = new StoreAdminForm(['mch_id' => $this->mch['id']]); $form->start_date = input_params('start_date'); $form->end_date = input_params('end_date'); $form->wechat = $this->wechat; $form->tab = input_params('tab'); $form->type = input_params('type'); $res = $form->shopData(); return $this->asJson($res); } //修改获取商城数据 public function actionGetStoreInfo() { $form = new StoreAdminForm(); $form->logo = post_params('logo'); $form->name = post_params('name'); $form->coordinate = post_params('coordinate'); $form->address = post_params('address'); $res = $form->getStoreInfo(); return $this->asJson($res); } //获取入驻商数据 public function actionMchInfo() { $mch_id = $this->mch['id']; $form = new MchForm(); $form->attributes = all_params(); $form->mch_id = $mch_id; $result = $form->mchInfo(); return $this->asJson($result); } //修改入驻商数据 public function actionMchInfoSave() { $mch_id = $this->mch['id']; $form = new MchForm(); $form->attributes = all_params(); $form->id = $mch_id; $result = $form->mchSave(); return $this->asJson($result); } public function actionMchQrcode() { $mch_id = $this->mch['id']; $form = new ShareQrcodeForm(); $form->store_id = get_store_id(); $form->type = \app\models\Qrcode::TYPE_MCH; $form->user = get_user(); $form->user_id = get_user_id(); $form->mch_id = $mch_id; return $this->asJson($form->search()); } /** * 提现 */ public function actionMchCashSubmit() { $price = input_params('cash'); $type = input_params('type', 0); $name = input_params('name', ''); $account = input_params('account', ''); $bank = input_params('bank', ''); $mch_id = $this->mch['id']; $form = new MchForm(); $form->attributes = all_params(); $form->mch_id = $mch_id; $result = $form->mchCashSubmit($price, $type, get_user_id(), $name, $account, $bank); return $this->asJson($result); } //店铺数据 public function actionGetYesData() { $form = new StoreAdminForm(['mch_id' => $this->mch['id']]); $form->start_date = input_params('start_date'); $form->end_date = input_params('end_date'); $form->wechat = $this->wechat; $res = $form->getYesData(); return $this->asJson($res); } //商品列表 public function actionGoodsList(){ $form = new StoreAdminGoodsForm(['mch_id' => $this->mch['id']]); $form->status = get_params('status',1); $form->sort = get_params('sort'); $res = $form->goodsList(); return $this->asJson($res); } //修改标题 public function actionSetGoodsName(){ $form = new StoreAdminGoodsForm(); $form->id = post_params('id'); $form->goods_name = post_params('name'); $res = $form->setGoodsName(); return $this->asJson($res); } //删除商品 public function actionGoodsDel(){ $form = new StoreAdminGoodsForm(); $form->id = post_params('id'); $res = $form->goodsDel(); return $this->asJson($res); } //分享商品 public function actionShareGoods(){ $form = new ShareQrcodeForm(); $form->goods_id = post_params('id'); $form->store_id = get_store_id(); $form->type = 0; $form->user = get_user(); $form->user_id = get_user_id(); return $this->asJson($form->search()); } //修改上下架状态 public function actionSetGoodsStatus(){ $form = new StoreAdminGoodsForm(); $form->id = post_params('id'); $form->status = post_params('status'); $res = $form->setGoodsStatus(); return $this->asJson($res); } //修改价格库存 public function actionSetGoodsPrice(){ $form = new StoreAdminGoodsForm(); $form->id = post_params('id'); $form->goods_price = post_params('goods_price', 0); $form->goods_num = post_params('goods_num', 0); $form->attr = post_params('attr', 0); $res = $form->setPrice(); return $this->asJson($res); } /** * 批量修改价格 */ public function actionUpPriceBatch() { $goods_id = input_params('goods_id'); $num = input_params('num'); $form = new \app\modules\admin\models\GoodsForm(); $form->store_id = get_store_id(); $res = $form->upPriceBatch($goods_id, $num); return $this->asJson($res); } //获取修改商品数据 public function actionGetGoodsEdit(){ $form = new StoreAdminGoodsForm(); $form->id = get_params('id'); $res = $form->getGoodsEdit(); return $this->asJson($res); } //修改订单价格 public function actionModifyPrice() { $form = new StoreAdminOrderForm(); $form->price = post_params("price"); $form->id = post_params("id"); $res = $form->ModifyPrice(); return $this->asJson($res); } //修改运费价格 public function actionExpressPrice() { $form = new StoreAdminOrderForm(); $form->express_price = post_params("express_price"); $form->id = post_params("id"); $res = $form->ExpressPrice(); return $this->asJson($res); } //获取运费规则 public function actionGetPostageData(){ $form = new StoreAdminGoodsForm(); $res = $form->getPostageData(); return $this->asJson($res); } //保存商品 public function actionSaveGoods(){ $form = new StoreAdminGoodsForm(['mch_id' => $this->mch['id']]); $form->goods_info = post_params('goods_info'); $res = $form->saveGoods(); return $this->asJson($res); } //商品详情 public function actionGoodsDetail(){ $form = new StoreAdminGoodsForm(); $form->id = post_params('id'); $res = $form->goodsDetail(); return $this->asJson($res); } //获取商品规格信息 public function actionGetGoodsAttr(){ $form = new StoreAdminGoodsForm(); $form->id = post_params('id'); $res = $form->getGoodsAttr(); return $this->asJson($res); } //分类列表 public function actionCatList() { $form = new StoreAdminGoodsForm(['mch_id' => $this->mch['id']]); $res = $form->catList(); return $this->asJson($res); } //分类添加保存 public function actionCatSave() { $form = new StoreAdminGoodsForm(['mch_id' => $this->mch['id']]); $form->cat_name = post_params("name"); $form->id = post_params("id"); $form->parent_id = post_params("parent_id", 0); $form->pic_url = post_params("pic_url"); $form->status = post_params("is_show", 1); $res = $form->catAdd(); return $this->asJson($res); } //分类修改状态 public function actionSetCatStatus() { $form = new StoreAdminGoodsForm(['mch_id' => $this->mch['id']]); $form->id = post_params("id"); $form->status = post_params("status", 0); $res = $form->setCatStatus(); return $this->asJson($res); } /** * 订单 */ //订单列表 public function actionOrderList() { $form = new StoreAdminOrderForm(['mch_id' => $this->mch['id']]); $form->status = get_params("status"); $form->date_range = (empty(get_params("begin_time")) || empty(get_params("end_time")))?false:[ 'begin_time' => get_params("begin_time"), 'end_time' => get_params("end_time") ]; $res = $form->orderList(); return $this->asJson($res); } //订单商品评价 public function actionOrderCommentGoodsList() { $form = new StoreAdminCommentForm(['mch_id' => $this->mch['id']]); $form->goods_name = get_params("goods_name"); $form->date_range = (empty(get_params("begin_time")) || empty(get_params("end_time")))?false:[ 'begin_time' => get_params("begin_time"), 'end_time' => get_params("end_time") ]; $res = $form->commentGoodsList(); return $this->asJson($res); } //订单评价 public function actionOrderCommentList() { $form = new StoreAdminCommentForm(); $form->goods_name = get_params("goods_name"); $form->goods_id = get_params("goods_id"); $form->status = get_params("status"); $form->type = get_params("type"); $res = $form->commentList(); return $this->asJson($res); } //删除评论 public function actionCommentDel() { $form = new StoreAdminCommentForm(); $form->id = post_params("id"); $res = $form->commentDel(); return $this->asJson($res); } //回复评论 public function actionCommentReply() { $form = new StoreAdminCommentForm(); $form->id = post_params("id"); $form->reply_content = post_params("reply_content"); $res = $form->commentReply(); return $this->asJson($res); } //取消订单 public function actionOrderCancel() { $form = new StoreAdminOrderForm(); $form->remark = post_params("remark"); $form->id = post_params("id"); $res = $form->orderCancel(); return $this->asJson($res); } //订单发货 public function actionOrderSend() { $form = new OrderSendForm(); $post = post_params(); if (($post['is_express'] == OrderSendForm::EXPRESS_TYPE_EXPRESS)) { $form->scenario = 'EXPRESS'; }elseif ($post['is_express'] == OrderSendForm::EXPRESS_TYPE_DADA){ $form->scenario = 'DADA'; }elseif ($post['is_express'] == OrderSendForm::EXPRESS_TYPE_UU){ $form->scenario = 'UU'; }elseif ($post['is_express'] == OrderSendForm::EXPRESS_TYPE_PEISONG){ $form->scenario = 'PEISONG'; } $form->attributes = $post; $form->store_id = get_store_id(); return $this->asJson($form->save()); } //售后订单 public function actionOrderRefund() { $form = new StoreAdminOrderForm(['mch_id' => $this->mch['id']]); $form->status = get_params("status", 0); $form->date_range = (empty(get_params("begin_time")) || empty(get_params("end_time")))?false:[ 'begin_time' => get_params("begin_time"), 'end_time' => get_params("end_time") ]; $res = $form->orderRefund(); return $this->asJson($res); } //订单详情 public function actionOrderDetail() { $form = new StoreAdminOrderForm(); $form->id = post_params("id"); $form->type = post_params("type", 0); $res = $form->orderDetail(); return $this->asJson($res); } //获取快递公司数据 public function actionGetExpress(){ $form = new StoreAdminOrderForm(); $res = $form->express(); return $this->asJson($res); } //售后订单处理 public function actionOrderRefundApply() { $form = new OrderRefundForm(); $form->order_refund_id = post_params("id"); $form->store_id = get_store_id(); $form->action = post_params("action", 0); $form->type = post_params("type", 1); $form->refund = post_params("refund", 0); $form->address_id = post_params("address_id", 0); $res = $form->save(); return $this->asJson($res); } //售后地址添加 public function actionRefundAddressSave() { $form = new StoreAdminOrderForm(); $form->id = post_params("id"); $form->mch_name = post_params("name"); $form->mch_mobile = post_params("mobile"); $form->mch_address = post_params("address"); $form->is_default = post_params("is_default", 0); $res = $form->refundAddressSave(); return $this->asJson($res); } //商家收货地址列表 public function actionRefundAddress() { $form = new StoreAdminOrderForm(); $res = $form->refundAddress(); return $this->asJson($res); } //商家收货地址删除 public function actionRefundAddressDel() { $form = new StoreAdminOrderForm(); $form->id = post_params("id"); $res = $form->refundAddressDel(); return $this->asJson($res); } //商家收货地址设置默认 public function actionRefundAddressDefault(){ $form = new StoreAdminOrderForm(); $form->id = post_params("id"); $res = $form->refundAddressDefault(); return $this->asJson($res); } //设置订单中的收货地址 public function actionSetRefundAddress(){ $form = new StoreAdminOrderForm(); $form->id = post_params("id"); $form->mch_address = post_params("address_id"); $res = $form->setRefundAddress(); return $this->asJson($res); } //获取单个收货地址 public function actionGetAddressInfo(){ $form = new StoreAdminOrderForm(); $form->id = post_params("id"); $res = $form->getAddressInfo(); return $this->asJson($res); } public function actionTemplateList() { $name = input_params('name', ''); $category_id = input_params('category_id', 0); $cond = ['is_delete' => 0]; $name && $cond['name'] = $name; $category_id && $cond['category_id'] = $category_id; $query = StoreTemplate::find()->where($cond); $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 actionTemplateInfo() { $store_id = get_store_id(); $id = input_params('id', 0); $model = StoreTemplate::findOne($id); $store_template_used = \app\models\Option::get('store_template_used', $store_id, 'saas', 0)['value']; $used = $store_template_used == $model->id ? 1 : 0; return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $model, 'used' => $used, ]); } public function actionTemplateUsed() { $store_id = get_store_id(); $id = input_params('id', 0); $type = input_params('type', ['home']);//home/category/product/center/all $model = StoreTemplate::findOne($id); $useTemp = $model->useTemp($store_id, $type); if($useTemp['code'] != 0){ return $useTemp; } if(in_array('all', $type)){ \app\models\Option::set('store_template_used', $id, $store_id, 'saas'); $model->use_count++; $model->save(); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $model, 'copy' => $useTemp, ]); } public function actionStoreCopyStatus() { $id = input_params('id', 0); $res = \app\models\StoreCopy::doCopyStatus($id); return $this->asJson($res); } //店铺初始化 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 = \app\models\StoreCopy::doCopy($default['store_id'], $id, $default['type']); return $this->asJson([ 'code' => 0, 'msg' => '操作成功' ]); } //生成token public function setToken($id) { $store_admin = StoreAdmin::findOne($id); $admin = Admin::findOne(['type' => Admin::ADMIN_TYPE_MINI_ADMIN, 'type_id' => $id, 'is_delete' => 0]); $time = time(); $payload = [ 'iss' => \Yii::$app->request->hostInfo, 'iat' => $time, 'exp' => $time + 86400, 'admin_id' => $admin->id, 'username' => $admin->username, 'store_admin_id' => $store_admin->id ]; return \Yii::$app->jwt->createToken($payload); } //扫码入库 public function actionErpScanGetGoodsList() { $form = new StoreAdminGoodsForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $res = $form->erpScanGetGoodsList(); return $this->asJson($res); } //erp入库 public function actionPurchaseInSave() { $form = new StoreAdminGoodsForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); $res = $form->purchaseInSave(); return $this->asJson($res); } //单品退款列表 public function actionOrderGoodsCancelList() { $form = new StoreAdminOrderForm(); $form->status = get_params('status'); $res = $form->orderGoodsCancelList(); return $this->asJson($res); } //前端后台管理员同意打款 public function actionOrderGoodsCancelHandle() { try { $id = post_params('id'); $status = post_params('status'); $result = \app\models\OrderGoodsCancel::orderGoodsCancelHandle($id, $status); return $this->asJson($result); } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } }