| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\controllers\v1;
- use app\jobs\StoreSyncJob;
- use app\models\Admin;
- use app\models\StoreAdmin;
- use app\modules\admin\models\AdminForm;
- use app\modules\admin\models\OrderRefundForm;
- use app\modules\admin\models\OrderSendForm;
- use app\models\StoreTemplate;
- use app\models\SaasCategory;
- use app\models\StoreCash;
- use app\modules\client\behaviors\StoreAdminLogin;
- use app\modules\client\controllers\BaseController;
- use app\modules\client\models\v1\ShareQrcodeForm;
- use app\modules\client\models\v1\store\StoreAdminCommentForm;
- use app\modules\client\models\v1\store\StoreAdminForm;
- use app\modules\client\models\v1\store\StoreAdminGoodsForm;
- use app\modules\client\models\v1\store\StoreAdminOrderForm;
- use yii\helpers\ArrayHelper;
- use app\modules\admin\models\MchForm;
- class StoreAdminController extends BaseController
- {
- public $mch = null;
- /**
- * @return array
- */
- public function behaviors()
- {
- $merge = [
- [
- 'class' => 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()
- ]);
- }
- }
- }
|