| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926 |
- <?php
- namespace addons\Store\api\modules\v2\controllers;
- use addons\PlatformStoreClerk\common\models\PlatformStoreClerkOrderDetail;
- use addons\ReservationService\common\enums\ReservationServiceEnum;
- use addons\ReservationService\common\logic\NoticeLogic;
- use addons\ReservationService\common\models\ReservationServiceOrder;
- use addons\ReservationService\common\models\ReservationServiceUser;
- use addons\ReservationService\common\models\ReservationServiceUserBookTime;
- use addons\ReservationService\common\services\OrderService;
- use addons\SecondaryCard\common\models\SecondaryCard;
- use addons\SecondaryCard\common\models\SecondaryCardOrder;
- use addons\SecondaryCard\common\models\SecondaryCardUseLog;
- use addons\SecondaryCard\common\service\SecondaryCardOrderService;
- use addons\SecondaryCard\common\service\SecondaryCardService;
- use addons\Store\common\models\Store;
- use addons\Store\common\models\StoreClerk;
- use addons\Store\common\models\StoreClerkLog;
- use addons\Store\common\models\StoreOrder;
- use addons\Store\common\models\StoreOrderDetail;
- use addons\Store\common\models\StoreOrderReserve;
- use common\enums\AddonsEnum;
- use common\enums\MarketingTypeEnum;
- use common\enums\OrderStatusEnum;
- use common\enums\PayTypeEnum;
- use common\enums\ShippingTypeEnum;
- use common\enums\StatusEnum;
- use common\globals\GlobalInvoke;
- use common\models\common\ClerkLog;
- use common\models\mall\MallAddons;
- use common\models\order\Order;
- use common\models\order\OrderDetail;
- use common\models\order\OrderExpress;
- use common\models\order\OrderMarketing;
- use common\models\order\OrderReserve;
- use common\models\user\Town;
- use common\models\user\User;
- use Yii;
- use addons\Store\common\enums\StoreEnum;
- use addons\Store\common\models\StoreCate;
- use addons\Store\common\services\StoreService;
- use common\models\common\Region;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Store\api\modules\v2\controllers
- */
- class StoreController extends BaseController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index', 'clerk', 'is-clerk', 'clerk-log', 'detail', 'setting', 'store-cate-tree', 'get-address-list', 'address-info', 'get-town-list',
- 'reservation-service-list', 'reservation-service-detail', 'reservation-service-talking', 'clerk-common', 'clerk-common-log', 'reservation-service-reject',
- 'clerk-common-log-detail',];
- public function actionIndex()
- {
- $store = $this->store;
- $data = [
- 'id' => $this->store_id,
- 'store_name' => $store['store_name'],
- 'shop_owner' => $store['shop_owner'],
- 'balance' => $store['balance'],
- 'unsettled_amount' => $store['unsettled_amount'],
- 'logo_img' => $store['logo_img'],
- 'shop_mobile' => $store['shop_mobile'],
- 'is_show_platform_store_clerk' => 0
- ];
- //是否显示核销统计【插件:门店核销】
- if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_PLATFORM_STORE_CLERK)) {
- $data['is_show_platform_store_clerk'] = 1;
- }
- return $this->success('success', $data);
- }
- //判断是否是核销员
- public function actionIsClerk()
- {
- $mall_id = $this->mall_id;
- $store = Store::getOne([['id' => $this->store_id]], true, [], false, 'id,user_id,balance');
- $user_id = $store['user_id'];
- $rse = StoreClerk::getOne([['mall_id' => $mall_id], ['user_id' => $user_id], ['status' => StatusEnum::ENABLED]]);
- if (empty($rse)) return $this->error('你不是核销员');
- return $this->success('操作成功', ['store_id' => $rse['store_id']]);
- }
- //核销
- public function actionClerk()
- {
- $params = Yii::$app->request->post();
- $store = Store::getOne([['id' => $this->store_id]], true, [], false, 'id,user_id,balance');
- $user_id = $store['user_id'];
- $storeService = new StoreService();
- $storeService->mall_id = $this->mall_id;
- $storeService->store_id = $this->store_id;
- $params['clerk_id'] = $storeService->getClerkIdByUserId($user_id, true);
- $mall_id = $this->mall_id;
- $params['mall_id'] = $mall_id;
- $rse = StoreClerk::getOne([['mall_id' => $mall_id], ['user_id' => $user_id], ['status' => StatusEnum::ENABLED]]);
- if (empty($rse)) return $this->error('你不是核销员');
- $params['store_id'] = $rse['store_id'];
- $rse = StoreClerkLog::setData($params);
- if ($rse == false) return $this->error(StoreClerkLog::getStaticError());
- return $this->success('操作成功');
- }
- // 已核销和未核销的订单
- public function actionClerkLog()
- {
- $params = \Yii::$app->request->get();
- $params['take_status'] = $params['take_status'] ?? 0;
- $order_params['order'] = 'id desc';
- $order_params['with'] = ['detail', 'base_user'];
- $order_params['select'] = 'id,mall_id,pay_money,store_id,shipping_type,order_no,order_status,user_id';
- $order_params['where'] = [
- ['mall_id' => $this->mall_id],
- ['store_id' => $this->store_id],
- ['shipping_type' => ShippingTypeEnum::PICKUP]
- ];
- if ($params['take_status'] == 1) { // 已核销
- $order_params['where'][] = ['order_status' => [OrderStatusEnum::TAKE_FINISH, OrderStatusEnum::ACCOMPLISH]];
- } else if ($params['take_status'] == 2) { // 待核销
- $order_params['where'][] = ['order_status' => OrderStatusEnum::TAKE];
- } else { // 全部
- $order_params['where'][] = ['order_status' => [OrderStatusEnum::TAKE, OrderStatusEnum::TAKE_FINISH, OrderStatusEnum::ACCOMPLISH]];
- }
- $order_params['limit'] = $params['limit'] ?? 10;
- $order_list = Order::listPage($order_params, false);
- $order_nos = array_column($order_list['list'], 'order_no');
- $clerk_log = StoreClerkLog::lists([
- 'where' => [['order_no' => $order_nos]],
- 'select' => '*',
- 'index' => 'order_no'
- ]);
- foreach ($order_list['list'] as $key => $item) {
- $item['nickname'] = $item['base_user']['nickname'] ?? '';
- $item['avatar_url'] = $item['base_user']['avatar_url'] ?? '';
- if (in_array($item['order_status'], [OrderStatusEnum::TAKE_FINISH, OrderStatusEnum::ACCOMPLISH])) {
- $item['clerk_status'] = '已核销';
- } else {
- $item['clerk_status'] = '待核销';
- }
- $item['details'] = $item['detail'];
- $item['total_num'] = count($item['detail']);
- $item['order_id'] = $item['id'];
- $item['clerk_id'] = '';
- if (isset($clerk_log[$item['order_no']])) {
- $clerk = $clerk_log[$item['order_no']];
- $item['clerk_id'] = $clerk['clerk_id'] ?? 0;
- $item['mobile'] = $clerk['mobile'] ?? '';
- }
- $item['mobile'] = $item['mobile'] ?? '';
- unset($item['detail'], $item['base_user']);
- $order_list['list'][$key] = $item;
- }
- return $this->success('操作成功', $order_list);
- }
- /**
- * 订单详情
- * @return mixed|void
- */
- public function actionDetail()
- {
- $params = \Yii::$app->request->get();
- $res = \Yii::$app->services->validate->validate($params, [
- [['order_id'], 'required'],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $store = Store::getOne([['id' => $this->store_id]], true, [], false, 'id,user_id,balance');
- // $user_id = $store['user_id'];
- $select = 'id,mall_id,store_id,order_no,receiver_name,mobile,pay_money,shipping_money,original_goods_price,coupon_money,goods_price,order_status,pay_status,
- shipping_status,review_status,is_feedback,address,created_at,pay_time,region_name,remark,consign_time,finish_time,sign_time,shipping_type,payment_type,score,score_money,marketing_id,marketing_type,extra_info,order_source';
- $where = [];
- $where[] = ['mall_id' => $this->mall_id];
- $where[] = ['or',
- ['id' => $params['order_id']],
- ['clerk_code' => $params['order_id']],
- ];
- $order = Order::getOne($where, true, ['detail' => function ($query) {
- $query->select('id,order_id,goods_id,goods_name,pic_url,num,price,is_feedback,sign_id,goods_attr_name,order_status,adjust_money,extra_info');
- }], false, $select);
- // $rse = StoreClerk::getOne([['mall_id' => $this->mall_id], ['user_id' => $user_id, 'store_id' => $order['store_id']], ['status' => StatusEnum::ENABLED]]);
- // if (empty($rse)) return $this->error('你不是核销员');
- if (empty($order)) return $this->error('该订单不存在', []);
- $marketing = OrderMarketing::getMarketingInfo($order);
- $order['order_status_text'] = OrderStatusEnum::getMap();
- $order['is_feedback_text'] = OrderStatusEnum::getFeedbackMap();
- $order['shipping_type_text'] = ShippingTypeEnum::getMap();
- $order['payment_type_text'] = PayTypeEnum::getMap();
- $order['pay_type_list'] = \Yii::$app->services->pay->getEnablePayment($this->mall_id, $this->platform);
- $adjust_money = array_sum(array_column($order['detail'], 'adjust_money'));//预留字段
- if ($adjust_money) {
- $order['change_price'] = $adjust_money;
- }
- $order['marketing'] = $marketing;
- $order['marketing_type_map'] = MarketingTypeEnum::getMap();
- $order_setting = Yii::$app->services->setting->mall->get($this->mall_id, 'order');
- $order['payment_expire_time'] = $order_setting['payment_expire_time'] ?? 30;
- $order['auto_receiving_time'] = $order_setting['auto_receiving_time'] ?? 14;
- // 获取订单详情的状态文字描述
- $order['status_text'] = OrderStatusEnum::getApiStatus($order['status'], $order['shipping_type']);
- $order['status'] == OrderStatusEnum::NOT_PAY && $order['status_text']['desc'] = $order['payment_expire_time'] . $order['status_text']['desc'];
- $order['status'] == OrderStatusEnum::SHIPMENTS && $order['status_text']['desc'] = $order['auto_receiving_time'] . $order['status_text']['desc'];
- $order['show_clerk_button'] = $order['order_status'] == OrderStatusEnum::TAKE ? 1:0;
- // 公共调用
- $order = GlobalInvoke::exec(GlobalInvoke::ORDER_DETAIL, $this->mall_id, [
- 'order' => $order,
- 'mall_id' => $this->mall_id,
- ]) ?: $order;
- return $this->success('操作成功', $order);
- }
- public function actionSetting()
- {
- if (Yii::$app->request->isGet) {
- $detail = Store::getOne([['id' => $this->store_id], ['mall_id' => $this->mall_id]], true);
- $detail['cIds'] = [];
- $detail['province'] = '';
- $detail['city'] = '';
- $detail['district'] = '';
- $detail['c_name'] = '';
- $c_name = '';
- if ($detail) {
- if (!empty($detail['c_id'])) {
- $cate = StoreCate::findOne(['mall_id' => $this->mall_id, 'id' => $detail['c_id']]);
- if (!empty($cate['parent_id'])) {
- $parent = StoreCate::findOne(['mall_id' => $this->mall_id, 'id' => $cate['parent_id']]);
- if (!empty($parent['parent_id'])) {
- $detail['cIds'][] = $parent['parent_id'];
- }
- if (!empty($parent['name'])) {
- $c_name .= $parent['name'] . '/';
- }
- $detail['cIds'][] = $cate['parent_id'];
- }
- $detail['cIds'][] = $detail['c_id'];
- $c_name .= $cate['name'];
- }
- $detail['c_name'] = $c_name;
- $region_id_arr = [$detail['province_id'], $detail['city_id'], $detail['district_id']];
- $region_list = Region::lists(['where' => [['id' => $region_id_arr]], 'index' => 'id', 'select' => 'id,name']);
- if (!empty($detail['province_id'])) {
- $detail['province'] = $region_list[$detail['province_id']]['name'];
- $detail['city'] = $region_list[$detail['city_id']]['name'];
- $detail['district'] = $region_list[$detail['district_id']]['name'];
- }
- }
- $detail['address_detail'] = $detail['address'] ?? '';
- $detail['ll'] = $detail['latitude'] . ',' . $detail['longitude'];
- if (!empty($detail['freight_type'])) {
- $detail['freight_type'] = json_decode($detail['freight_type'], true);
- } else {
- $detail['freight_type'] = [
- 'express_delivery' => 0,
- 'merchant_distribution' => 0,
- 'self_mention' => 0,
- ];
- }
- if (!empty($detail['intra_city_distribution'])) {
- $detail['intra_city_distribution'] = json_decode($detail['intra_city_distribution'], true);
- } else {
- $detail['intra_city_distribution'] = ['distribution_scope' => 0, 'initial_delivery_amount' => 0, 'full_money' => 0, 'reduce_money' => 0, 'distribution_fee' => 0];
- }
- if (!empty($detail['introduce'])) {
- $detail['introduce'] = json_decode($detail['introduce'], true);
- } else {
- $detail['introduce'] = [];
- }
- if (!empty($detail['bannar_pic'])) {
- $detail['bannar_pic'] = json_decode($detail['bannar_pic'], true);
- } else {
- $detail['bannar_pic'] = [];
- }
- if (!isset($detail['show_style'])) {
- $detail['show_style'] = "1";
- }
- $platform_address = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'basic.platform_address');
- $detail['platform_address'] = $platform_address ?? '';
- return $this->success('操作成功', ['detail' => $detail]);
- }
- if (Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- $params['id'] = $this->store_id;
- $params['mall_id'] = $this->mall_id;
- // $params['freight_type'] = [
- // "express_delivery" => 0,
- // "merchant_distribution" => 0,
- // "self_mention" => 1
- // ];
- if (isset($params['longitude'])) $params['longitude'] = (string)$params['longitude'];
- if (isset($params['latitude'])) $params['latitude'] = (string)$params['latitude'];
- if (isset($params['shop_mobile'])) $params['shop_mobile'] = (string)$params['shop_mobile'];
- if (isset($params['shop_owner'])) $params['shop_owner'] = (string)$params['shop_owner'];
- if (isset($params['device_id'])) $params['device_id'] = (string)$params['device_id'];
- if (isset($params['store_desc'])) $params['store_desc'] = (string)$params['store_desc'];
- if (empty($params['introduce'])) unset($params['introduce']);
- if (empty($params['bannar_pic'])) unset($params['bannar_pic']);
- $res = Store::setData($params);
- if ($res == false) return $this->success(Store::getStaticError());
- return $this->success('操作成功');
- }
- }
- public function actionGetAddressList()
- {
- $get = Yii::$app->request->get();
- if (!empty($get['id'])) $where[] = ['parent_id' => $get['id']];
- if (empty($get['level'])) {
- $level = 1;
- } else {
- $level = $get['level'];
- }
- $where[] = ['level' => $level];
- $params['where'] = $where;
- $params['select'] = 'id,name,parent_id,level,lng,lat';
- $list = Region::lists($params);
- return $this->success('操作成功', $list);
- }
- public function actionStoreCateTree()
- {
- if (Yii::$app->request->isGet) {
- $cond = [['mall_id' => $this->mall_id]];
- $list = StoreCate::getCates($cond, [], true, 'id,name,parent_id');
- $list = StoreCate::getTreeCate($list);
- return $this->success('操作成功', compact('list'));
- }
- }
- /**
- * 获取省市区数据
- * @return \yii\web\Response
- */
- public function actionAddressInfo()
- {
- $list = Region::getRegionList([['<>', 'parent_id', -1]], 'id,name,parent_id,level', [], 1);
- return $this->success('ok', $list);
- }
- /**
- * 获取乡镇列表
- * @return mixed|void
- */
- public function actionGetTownList()
- {
- $params = Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($params, [
- [['district_id'], 'required', 'message' => 'district_id必传'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where[] = ['district_id' => !empty($params['district_id']) ? $params['district_id'] : ''];
- $params['order'] = 'id desc';
- $params['select'] = 'id,adcode,name';
- $params['where'] = $where;
- $page_data = Town::listPage($params, false);
- return $this->success('操作成功', $page_data);
- }
- /**
- * 获取验证码
- *
- * @return void
- */
- public function actionGetCaptcha()
- {
- $service = new StoreService(['mall_id' => $this->mall_id, 'store_id' => $this->store_id]);
- return $service->sendCaptcha()
- ? $this->success('发送成功')
- : $this->error($service->getError());
- }
- /**
- * 修改密码
- *
- * @return void
- */
- public function actionChangePwd()
- {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['captcha'], 'required', 'message' => '验证码不能为空'],
- [['password'], 'required', 'message' => '修改密码不能为空'],
- ]);
- if ($res === false) {
- return $this->error(Yii::$app->services->validate->getErrorMessage());
- }
- $service = new StoreService(['mall_id' => $this->mall_id, 'store_id' => $this->store_id]);
- return $service->changePwd($params['captcha'], $params['password'])
- ? $this->success('修改成功')
- : $this->error($service->getError());
- }
- /**
- * 兑换管理 :是否显示
- */
- public function actionCheckExchange()
- {
- $is_show = 0;
- if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_GOLD_BADGE) !== 0) {
- $config = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_GOLD_BADGE, 'basic');
- $is_show = $config['is_enable'] ?? 0;
- }
- return $this->success('操作成功', ['is_show' => $is_show]);
- }
- public function actionPlatformClerkList()
- {
- if (Yii::$app->request->isGet) {
- $get = Yii::$app->request->get();
- if (!MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_PLATFORM_STORE_CLERK)) {
- return $this->success('获取成功', []);
- }
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($get, [
- [['page', 'limit'], 'integer'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['=', 'clerk_store_id', $this->store_id];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $order = 'id desc,created_at desc';
- $select = 'id,order_id,order_detail_id,reward_num,clerk_time,clerk_user_id,user_id';
- $with = ['orderDetail', 'order', 'clerkUser', 'user'];
- $params = array('where' => $where, 'order' => $order, 'select' => $select, 'with' => $with, 'limit' => $get['limit'] ?? 10, 'page' => $get['page'] ?? 1);
- $list = PlatformStoreClerkOrderDetail::listPage($params);
- foreach ($list['list'] as &$item) {
- $item['reward_num'] = $item['reward_num'] ?: 0;
- $item['clerk_time'] = date('Y-m-d H:i:s', $item['clerk_time']);
- $item['goods_name'] = $item['orderDetail']['goods_name'] ?? '';
- $item['order_no'] = $item['order']['order_no'] ?? '';
- //$item['user'] = $user;
- $item['clerk_user_info'] = '核销员' . $item['clerkUser']['nickname'] . '(id:' . $item['clerk_user_id'] . ')';
- unset($item['order'], $item['orderDetail'], $item['clerkUser']);
- }
- return $this->success('获取成功', $list);
- }
- }
- /**
- * 预约管理
- * @Author:hua
- * @Date:2024-03-06 18:05
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|void
- */
- public function actionReservationServiceList()
- {
- $data = Yii::$app->request->get();
- $valid = Yii::$app->services->validate->validate($data, [
- [['limit', 'page', 'order_status'], 'integer'],
- ]);
- if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $data['store_id'] = $this->store_id;
- $ret = $this->page($this->mall_id, $data);
- return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
- }
- protected function page(int $mall_id, array $params)
- {
- if (!MallAddons::isInstall($mall_id, 'SecondaryCard')) {
- return '请先安装次卡插件';
- }
- if (!MallAddons::isInstall($mall_id, 'ReservationService')) {
- return '请先安装预约服务插件';
- }
- $where = [
- ['mall_id' => $mall_id],
- ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
- ['!=','service_status', ReservationServiceEnum::RESERVE_ORDER_STATUS_CLOSED ],
- ['store_id' => $params['store_id']],
- ['reservation_model' => 1],
- ['!=', 'secondary_card_id', 0]
- ];
- if (isset($params['order_status']) && $params['order_status'] !== '' && $params['order_status'] != 999) {
- $where[] = ['service_status' => $params['order_status']];
- }
- $with = [
- ];
- $ret = ReservationServiceOrder::listPage([
- 'where' => $where,
- 'order' => 'id desc',
- 'limit' => $params['limit'] ?? 10,
- 'with' => $with
- ]);
- if (!empty(ReservationServiceOrder::getStaticError())) return ReservationServiceOrder::getStaticError();
- $ret['status_text_map'] = ReservationServiceEnum::RESERVE_ORDER_STATUS_MAP;
- if (!empty($ret['list'])) {
- $mall_name = Yii::$app->services->setting->mall->get($mall_id, 'basic.name');
- $mall_logo = Yii::$app->services->setting->mall->get($mall_id, 'basic.logo');
- $user_ids = array_column($ret['list'],'user_id');
- $user_list = User::lists(['where'=>[['id'=>$user_ids]],'index'=>'id']);
- $secondary_card_order_list = [];
- //次卡部分----start
- if (MallAddons::isInstall($mall_id, 'SecondaryCard')) {
- $secondary_card_no_arr = array_column($ret['list'], 'secondary_card_no');
- $secondary_card_order_list = SecondaryCardOrder::lists([
- 'where' => [
- ['order_no' => $secondary_card_no_arr],
- ],
- 'with' => ['secondaryCard'],
- 'index' => 'order_no'
- ]);
- }
- $reservation_service_order_ids = array_column($ret['list'], 'id');
- // $use_log_list = SecondaryCardUseLog::lists(['where' => [['reservation_service_order_id' => $reservation_service_order_ids]], 'index' => 'reservation_service_order_id']);
- foreach ($ret['list'] as &$item) {
- $item['status_text'] = ReservationServiceEnum::RESERVE_ORDER_STATUS_MAP[$item['service_status']];
- // $item['service_status'] = ReservationServiceEnum::RESERVE_ORDER_STATUS_MAP[$item['service_status']];
- $item['service_start_at_text'] = "";
- if (!empty($item['service_start_at'])) $item['service_start_at_text'] = date('Y-m-d H:i', $item['service_start_at']);
- $item['mall_name'] = $mall_name;
- $item['mall_logo'] = $mall_logo;
- $store = Store::findOne(['id' => $item['store_id']]);
- $item['mall_name'] = $store->store_name;
- $item['mall_logo'] = $store->logo_img;
- $reserveOrder = StoreOrderReserve::findOne(['main_order_id' => $item['order_id']]);
- $item['service_type'] = $reserveOrder->service_type;
- $item['service_type_text'] = ReservationServiceEnum::SERVICE_TYPE_MAP[$reserveOrder->service_type] ?? '未知服务';
- //次卡部分----start
- if (!empty($secondary_card_order_list) && isset($secondary_card_order_list[$item['secondary_card_no']])) {
- $secondary_card_order = $secondary_card_order_list[$item['secondary_card_no']];
- $secondary_card = [
- 'name' => $secondary_card_order['secondaryCard']['name'],
- 'font_color' => $secondary_card_order['secondaryCard']['font_color'],
- 'background' => $secondary_card_order['secondaryCard']['background'],
- 'appointment_interval_duration' => $secondary_card_order['secondaryCard']['appointment_interval_duration'],
- 'price' => $secondary_card_order['secondaryCard']['price'],
- 'times' => 1,
- 'order_no' => $secondary_card_order['order_no'],
- 'reservation_service_order_id' => $item['id'],
- ];
- // $secondary_card['service_times'] = $use_log_list[$item['id']]['clerk_nums'] ?? 1;
- // $secondary_card['service_money'] = $use_log_list[$item['id']]['service_income'] ?? 0;
- $secondary_card['service_type_text'] = '到店服务';
- $secondary_card['service_start_at_text'] = $item['service_start_at_text'];
- $secondary_card['status_text'] = $item['status_text'];
- $secondary_card['status'] = $item['service_status'];
- $secondary_card['mall_name'] = $item['mall_name'];
- $secondary_card['mall_logo'] = $item['mall_logo'];
- $secondary_card['order_id'] = $item['order_id'];
- $secondary_card['nickname'] = $user_list[$item['user_id']]['nickname'];
- $secondary_card['avatar_url'] = $user_list[$item['user_id']]['avatar_url'];
- $item = $secondary_card;
- }
- //次卡部分----end
- }
- }
- return $ret;
- }
- /**
- * 预约订单详情
- * @Author:hua
- * @Date:2024-03-06 18:21
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|void
- */
- public function actionReservationServiceDetail()
- {
- $data = Yii::$app->request->get();
- $valid = Yii::$app->services->validate->validate($data, [
- [['id'], 'integer'],
- [['id'], 'required']
- ]);
- if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $ret = $this->getDetailById($this->mall_id, $this->store_id, $data['id']);
- return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
- }
- protected function getDetailById(int $mall_id, int $store_id, int $id)
- {
- if (!MallAddons::isInstall($mall_id, 'SecondaryCard')) {
- return '请先安装次卡插件';
- }
- if (!MallAddons::isInstall($mall_id, 'ReservationService')) {
- return '请先安装预约服务插件';
- }
- $rWhere = [
- ['mall_id' => $mall_id],
- ['id' => $id],
- ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
- ['store_id' => $store_id]
- ];
- $model = ReservationServiceOrder::getOne($rWhere);
- if (empty($model)) return '预约记录不存在';
- $order_no = Order::find()->where(['mall_id' => $mall_id])
- ->andWhere(['id' => $model->order_id])
- ->select('order_no')->scalar();
- if (empty($order_no)) return '订单不存在.';
- $storeOrder = StoreOrder::findOne(['mall_id' => $mall_id, 'store_id' => $model->store_id, 'order_no' => $order_no]);
- if (empty($storeOrder)) return '订单不存在!';
- $orderReserve = StoreOrderReserve::getOne([
- ['mall_id' => $mall_id],
- ['reserve_type' => StatusEnum::ENABLED],
- ['order_id' => $storeOrder->id]
- ]);
- if (empty($orderReserve)) return '订单不存在';
- $order = (new OrderService())->orderDetail($mall_id, $model->order_id);
- if (is_array($order)) {
- $order['user'] = $model->getUser()->select('id, nickname, avatar_url, mobile')->one()->toArray();
- $order['reserve'] = $orderReserve->toArray();
- $order['service_status_map'] = ReservationServiceEnum::RESERVE_ORDER_STATUS_MAP;
- $order['service_status_text'] = $order['service_status_map'][$model->service_status] ?? '未知状态';
- $order['service_start_at_text'] = date('Y-m-d H:i', $model->service_start_at);
- $order['service_min'] = ($model->service_end_at - $model->service_start_at) / 60; // 分钟
- $order['service_status'] = $model->service_status;
- $order['service_type'] = $orderReserve->service_type; // 是否为上面服务
- $order['commission'] = bcmul($model->commission, 1, 2); // 是否为上门服务
- $order['service_type_text'] = ReservationServiceEnum::SERVICE_TYPE_MAP[$orderReserve->service_type] ?? '未知服务';
- if (!empty($order['finish_time'])) date('Y-m-d H:i:s', $order['finish_time']);
- if (!empty($order['sign_time'])) date('Y-m-d H:i:s', $order['sign_time']);
- }
- //次卡部分
- if (!empty($model->secondary_card_id)) {
- $secondary_card = SecondaryCard::findOne(['id' => $model->secondary_card_id]);
- $order['secondary_card'] = [
- 'name' => $secondary_card['name'],
- 'background' => $secondary_card['background'],
- 'font_color' => $secondary_card['font_color'],
- 'service' => json_decode($secondary_card['service'], true),
- 'secondary_card_no' => $model->secondary_card_no,
- ];
- $order['service_type_text'] = \addons\ReservationService\common\services\SecondaryCardService::getServiceTypeText($secondary_card);
- $secondary_card_order = SecondaryCardOrder::findOne(['order_no' => $model->secondary_card_no]);
- $order['secondary_card']['verifiable_times'] = $secondary_card_order['verifiable_times'];
- $order['secondary_card']['use_times'] = $secondary_card['verifiable_times'] - $secondary_card_order['verifiable_times'];
- $order['secondary_card']['clerk_code'] = $secondary_card_order['clerk_code'];
- $order['secondary_card']['order_source'] = SecondaryCardOrderService::getSourceName($secondary_card_order, $secondary_card['use_type']);
- $use_log = SecondaryCardUseLog::findOne(['reservation_service_order_id' => $model['id']]);
- $order['secondary_card']['service_times'] = $use_log['clerk_nums'] ?? 1;
- $order['secondary_card']['service_income'] = $use_log['service_income'] ?? 0;
- $order['secondary_card']['clerk_money'] = $use_log['clerk_money'] ?? bcdiv($secondary_card_order['pay_money'], $secondary_card['verifiable_times'], 2);
- $order['secondary_card']['pay_money'] = $secondary_card_order['pay_money'];
- $order['secondary_card']['reservation_service_order_id'] = $id;
- $order['secondary_card']['service_type_text'] = $order['service_type_text'];
- $order['secondary_card']['service_status_text'] = $order['service_status_text'];
- $order['secondary_card']['status'] = $order['service_status'];
- $order['secondary_card']['service_start_at_text'] = $order['service_start_at_text'];
- $order['secondary_card']['service_min'] = $order['service_min'];
- $order['secondary_card']['created_at'] = $order['created_at'];
- $order['secondary_card']['mall_name'] = $order['mall_name'];
- $order['secondary_card']['mall_logo'] = $order['mall_logo'];
- $order['secondary_card']['pay_time'] = date('Y-m-d H:i:s', $secondary_card_order['open_time']);
- }
- return $order['secondary_card'];
- }
- /**
- * 确认订单-接受
- * @Author:hua
- * @Date:2024-03-06 18:22
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|void
- */
- public function actionReservationServiceTalking()
- {
- $data = Yii::$app->request->get();
- $valid = Yii::$app->services->validate->validate($data, [
- [['id'], 'integer'],
- [['id'], 'required'],
- ]);
- if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $ret = $this->talking($this->mall_id, $this->store_id, $data['id']);
- return is_string($ret) ? $this->error($ret) : $this->success('操作成功');
- }
- /**
- * 拒绝接单
- * @return mixed|null
- */
- public function actionReservationServiceReject()
- {
- $data = Yii::$app->request->post();
- $valid = Yii::$app->services->validate->validate($data, [
- [['id'], 'integer'],
- [['reason'], 'string'],
- [['id'], 'required']
- ]);
- if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $ret = $this->reject($this->mall_id, $this->store['user_id'], $data['id'], 0, !empty($data['reason']) ? $data['reason'] : '无');
- return is_string($ret) ? $this->error($ret) : $this->success('操作成功');
- }
- /**
- * 拒绝接单
- * @Author:hua
- * @Date:2024-03-14 15:41
- * @Copyright:copyright(c)2024 广东七件事集团
- * @param $mall_id
- * @param $user_id
- * @param $order_id
- * @param int $store_id
- * @param string $reason
- * @return ReservationServiceOrder|string
- */
- public function reject( $mall_id, $user_id, $order_id, $store_id = 0, $reason = '无')
- {
- $where = [
- ['mall_id' => $mall_id],
- ['id' => $order_id],
- ['status' => StatusEnum::ENABLED],
- ['service_status' => ReservationServiceEnum::RESERVE_ORDER_STATUS_NORMAL]
- ];
- if (!empty($store_id)) $where[] = ['store_id' => $store_id];
- /**
- * @var $model ReservationServiceOrder
- */
- $model = ReservationServiceOrder::getOne($where);
- if (empty($model)) return '预约记录不存在';
- $store_name = $this->store['store_name'];
- $t = \Yii::$app->db->beginTransaction();
- try {
- $model->service_status = ReservationServiceEnum::RESERVE_ORDER_STATUS_REJECT;
- $model->remark = "{$model->remark} 门店 [$store_name] 拒绝了当前次卡的预约, 拒绝理由[$reason] \n";
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- $order = Order::findOne(['id'=>$model->order_id]);
- $order->status = StatusEnum::DISABLED;
- $order->save();
- StoreOrder::updateAll(['status'=>StatusEnum::DISABLED],['order_no'=>$order->order_no]);
- $t->commit();
- // 记录数据
- return $model;
- } catch (\Exception $e) {
- $t->rollBack();
- return $e->getMessage();
- }
- }
- public function talking(int $mall_id, int $store_id, int $order_id)
- {
- $where = [
- ['mall_id' => $mall_id],
- ['id' => $order_id],
- ['status' => StatusEnum::ENABLED],
- ['store_id' => $store_id],
- ['service_status' => ReservationServiceEnum::RESERVE_ORDER_STATUS_NORMAL]
- ];
- $model = ReservationServiceOrder::getOne($where);
- if (empty($model)) return '预约记录不存在';
- try {
- $store_order_reserve = StoreOrderReserve::findOne(['main_order_id' => $model['order_id']]);
- if (empty($store_order_reserve)) throw new \Exception("预约订单不存在");
- $store_order_reserve->reserve_status = StatusEnum::ENABLED;
- $store_order_reserve->reserve_date_time = date('Y-m-d H:i', $model->service_start_at) . ',' . date('Y-m-d H:i', $model->service_end_at);
- if (!$store_order_reserve->save()) throw new \Exception($store_order_reserve->getErrorMessage());
- $order_reserve = OrderReserve::findOne(['order_id' => $model['order_id']]);
- if (empty($order_reserve)) throw new \Exception("预约订单不存在");
- $order_reserve->reserve_status = StatusEnum::ENABLED;
- $order_reserve->reserve_date_time = date('Y-m-d H:i', $model->service_start_at) . ',' . date('Y-m-d H:i', $model->service_end_at);
- if (!$order_reserve->save()) throw new \Exception($store_order_reserve->getErrorMessage());
- // 执行发货操作
- $user = User::findOne(['id' => $this->store['user_id']]);
- $form = [];
- $form['mall_id'] = $model->mall_id;
- $form['mch_id'] = 0;
- $form['shipping_type'] = 0;
- $form['id'] = $model->order_id;
- $form['operator_id'] = $this->store['user_id'];
- $form['order_detail_ids'] = OrderDetail::find()->where(['order_id' => $model->order_id])->select('id')->column();
- $form['operator_name'] = $user['nickname'];
- $res = OrderExpress::delivery($form); // 发货
- if($res==false) {
- throw new \Exception(OrderExpress::getStaticError());
- }
- $form = [];
- $form['mall_id'] = $mall_id;
- $form['shipping_type'] = 0;
- $form['mch_id'] = 0;
- $form['store_id'] = $model->store_id;
- $form['operator_id'] = $this->store['user_id'];
- $form['operator_name'] = $user['nickname'];
- $form['id'] = $store_order_reserve->order_id;
- $form['order_detail_ids'] = StoreOrderDetail::find()->where(['order_id' => $store_order_reserve->order_id])->select('id')->column();
- $res = StoreOrder::OrderExpressDelivery($form);
- if (!$res) throw new \Exception(StoreOrder::getStaticError());
- $model->service_status = ReservationServiceEnum::RESERVE_ORDER_STATUS_TALKING;
- $model->server_status = ReservationServiceEnum::ARRIVED_AT_STORE;
- $model->remark = "{$model->remark} 门店 [$store_id] 接受了当前订单的预约 \n";
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- return $e->getMessage() . $e->getFile() . $e->getLine();
- }
- }
- /**
- * 公共核销
- * @Author:hua
- * @Date:2024-03-09 09:32
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|void
- */
- public function actionClerkCommon()
- {
- try {
- $request = \Yii::$app->request;
- if ($request->isGet) {
- $params = $request->get();
- $params['method'] = 'get';
- $params['platform'] = $this->platform;
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = $this->store['user_id'];
- $params['store_id'] = $this->store_id;
- $params['from'] = 'store_mobile_terminal';
- $result = GlobalInvoke::exec(GlobalInvoke::INVOKE_CLERK, $this->mall_id, $params);
- if (empty($result)) return $this->error('获取数据失败');
- return $this->success('操作成功', $result);
- }
- if ($request->isPost) {
- $params = $request->post();
- $params['method'] = 'post';
- $params['platform'] = $this->platform;
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = $this->store['user_id'];
- $params['store_id'] = $this->store_id;
- $params['from'] = 'store_mobile_terminal';
- $result = GlobalInvoke::exec(GlobalInvoke::INVOKE_CLERK, $this->mall_id, $params);
- if (empty($result)) return $this->error('核销失败');
- return $this->success('操作成功', $result);
- }
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- /**
- * 公共核销记录
- * @Author:hua
- * @Date:2024-03-09 11:58
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|void
- */
- public function actionClerkCommonLog()
- {
- $params = \Yii::$app->request->get();
- $where[] = ['mall_id' => $this->mall_id];
- $where[] = ['user_id' => $this->store['user_id']];
- $where[] = ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]];
- $params['where'] = $where;
- $params['order'] = 'id DESC';
- $params['select'] = 'id,mall_id,user_id,name,pic,mall_logo,mall_name,clerk_code,type,extra,created_at';
- $pageData = ClerkLog::getPageLists($params);
- return $this->success('操作成功', $pageData);
- }
- public function actionClerkCommonLogDetail()
- {
- try {
- $params = \Yii::$app->request->get();
- $res = \Yii::$app->services->validate->validate($params, [
- [['clerk_log_id', 'type'], 'required'],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $params['platform'] = $this->platform;
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = $this->store['user_id'];
- $result = GlobalInvoke::exec(GlobalInvoke::INVOKE_CLERK_DETAIL, $this->mall_id, $params);
- if (empty($result)) return $this->error('获取数据失败');
- return $this->success('操作成功', $result);
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
|