From 92076147f8c14774c1d73c0802bb022980c9a110 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Mon, 5 Feb 2024 13:58:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E8=B5=A0=E9=80=81=E5=8F=8A=E6=A0=B8=E9=94=80=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/store/coupon/StoreCouponUser.php | 15 +++++ .../store/coupon/StoreCouponOffRepository.php | 25 +++++++- .../store/coupon/StoreCouponRepository.php | 39 +++++++++-- .../coupon/StoreCouponUserRepository.php | 41 +++++++----- .../store/service/StoreServiceRepository.php | 64 ++++++++++++------- .../api/store/merchant/Merchant.php | 7 ++ .../api/store/product/StoreCoupon.php | 4 +- app/controller/api/user/Exchange.php | 16 +++++ app/listener/giveCoupon/CardOpeningEvent.php | 2 +- .../merchant/StoreServiceValidate.php | 10 +-- crmeb/listens/AutoCancelGroupOrderListen.php | 2 +- route/api.php | 2 + 12 files changed, 171 insertions(+), 56 deletions(-) diff --git a/app/common/model/store/coupon/StoreCouponUser.php b/app/common/model/store/coupon/StoreCouponUser.php index d057cb9..0ca5912 100644 --- a/app/common/model/store/coupon/StoreCouponUser.php +++ b/app/common/model/store/coupon/StoreCouponUser.php @@ -8,6 +8,7 @@ namespace app\common\model\store\coupon; use app\common\model\BaseModel; use app\common\model\system\merchant\Merchant; +use app\common\model\system\merchant\MerchantBrand; use app\common\model\user\User; /** @@ -58,4 +59,18 @@ class StoreCouponUser extends BaseModel { return $this->hasOne(Merchant::class, 'mer_id', 'mer_id'); } + + public function shopMer() + { + return $this->hasOne(Merchant::class, 'mer_id', 'shop_mer_id'); + } + + public function brand() + { + return $this->hasOne(MerchantBrand::class, 'id', 'brand_id'); + } + + + + } diff --git a/app/common/repositories/store/coupon/StoreCouponOffRepository.php b/app/common/repositories/store/coupon/StoreCouponOffRepository.php index 2b02a83..20b362c 100644 --- a/app/common/repositories/store/coupon/StoreCouponOffRepository.php +++ b/app/common/repositories/store/coupon/StoreCouponOffRepository.php @@ -7,6 +7,7 @@ namespace app\common\repositories\store\coupon; use app\common\dao\store\coupon\StoreCouponOffDao; +use app\common\model\store\service\StoreService; use app\common\repositories\BaseRepository; use think\exception\ValidateException; use think\facade\Db; @@ -38,8 +39,28 @@ class StoreCouponOffRepository extends BaseRepository { return $this->dao->create($data); } + /** + * Common: 判断:当前用户是否有核销权限 + * Author: wu-hui + * Time: 2024/02/05 11:51 + * @param $coupon + * @param $uid + * @return bool + */ + public function validateWriteOff($coupon, $uid){ + // 判断:是否存在酒道馆;存在则判断当前用户在当前酒道馆是否存在核销权限,不存在判断用户在其他酒道馆是否存在核销权限 + $shopMerId = $coupon->shop_mer_id ?? 0; + $isHas = StoreService::where('StoreService.uid', $uid) + ->hasWhere('merchant',function($query){ + $query->where('merchant_type',1); + }) + ->when((int)$shopMerId > 0,function($query) use ($shopMerId){ + $query->where('StoreService.mer_id', (int)$shopMerId); + }) + ->where('StoreService.is_verify',1) + ->count(); + if($isHas <= 0) throw new ValidateException('无核销权限!'); - public function validateWriteOff(){ - + return true; } } diff --git a/app/common/repositories/store/coupon/StoreCouponRepository.php b/app/common/repositories/store/coupon/StoreCouponRepository.php index 814fdb4..6a97480 100644 --- a/app/common/repositories/store/coupon/StoreCouponRepository.php +++ b/app/common/repositories/store/coupon/StoreCouponRepository.php @@ -63,6 +63,7 @@ class StoreCouponRepository extends BaseRepository //会员券 const GET_COUPON_TYPE_SVIP = 5; + /** * @var StoreCouponDao */ @@ -296,11 +297,35 @@ class StoreCouponRepository extends BaseRepository $this->sendCoupon($coupon, $uid,StoreCouponUserRepository::SEND_TYPE_RECEIVE); } - public function sendCoupon(StoreCoupon $coupon, $uid, $type) + // 购买会员卡赠送优惠券 支持重复赠送 + public function buyMembershipCardGive($id, $order){ + $uid = $order['uid']; + $coupon = $this->dao->validSvipCoupon($id,$uid); + if (!$coupon) throw new ValidateException('优惠券失效'); + // 获取酒道馆id 和关联的品牌ID + $bindShop = []; + if((int)$order['bind_mer_id'] > 0){ + $bindShop = app()->make(MerchantRepository::class)->getSearch([]) + ->where('shop_mer_id', $order['bind_mer_id']) + ->where('is_del', 0) + ->findOrEmpty() + ->toArray(); + } + $params = [ + 'shop_mer_id' => $bindShop['mer_id'] ?? 0, + 'brand_id' => $bindShop['brand_id'] ?? 0, + 'user_order_id' => $order['order_id'] ?? 0, + ]; + + $this->sendCoupon($coupon, $uid,StoreCouponUserRepository::SEND_TYPE_BUY, $params); + } + + + public function sendCoupon(StoreCoupon $coupon, $uid, $type, $params = []) { event('user.coupon.send.before', compact('coupon', 'uid', 'type')); - Db::transaction(function () use ($uid, $type, $coupon) { - $this->preSendCoupon($coupon, $uid, $type); + Db::transaction(function () use ($uid, $type, $coupon, $params) { + $this->preSendCoupon($coupon, $uid, $type, $params); app()->make(StoreCouponIssueUserRepository::class)->issue($coupon['coupon_id'], $uid); if ($coupon->is_limited) { $coupon->remain_count--; @@ -311,9 +336,13 @@ class StoreCouponRepository extends BaseRepository event('user.coupon.send.' . $type, compact('coupon', 'uid', 'type')); } - public function preSendCoupon(StoreCoupon $coupon, $uid, $type = 'send') - { + public function preSendCoupon(StoreCoupon $coupon, $uid, $type = 'send', $params = []){ $data = $this->createData($coupon, $uid, $type); + + $data['shop_mer_id'] = $params['shop_mer_id'] ?? 0; + $data['brand_id'] = $params['brand_id'] ?? 0; + $data['user_order_id'] = $params['user_order_id'] ?? 0; + return app()->make(StoreCouponUserRepository::class)->create($data); } diff --git a/app/common/repositories/store/coupon/StoreCouponUserRepository.php b/app/common/repositories/store/coupon/StoreCouponUserRepository.php index a374120..1745017 100644 --- a/app/common/repositories/store/coupon/StoreCouponUserRepository.php +++ b/app/common/repositories/store/coupon/StoreCouponUserRepository.php @@ -55,19 +55,28 @@ class StoreCouponUserRepository extends BaseRepository * @author xaboy * @day 2020/6/3 */ - public function userList(array $where, $page, $limit) - { - if ($page == 1) { - $this->dao->failCoupon(); - } + public function userList(array $where,$page,$limit){ + + if($page == 1) $this->dao->failCoupon(); $query = $this->dao->search($where); $count = $query->count(); - $list = $query->with(['coupon' => function ($query) { - $query->field('coupon_id,type,send_type'); - }, 'merchant' => function ($query) { - $query->field('mer_id,mer_name,mer_avatar'); - }])->page($page, $limit)->select(); - return compact('count', 'list'); + $list = $query->with([ + 'coupon' => function($query){ + $query->field('coupon_id,type,send_type'); + }, + 'merchant' => function($query){ + $query->field('mer_id,mer_name,mer_avatar'); + }, + 'shopMer' => function($query){ + $query->field('mer_id,mer_name,mer_avatar'); + }, + 'brand' => function($query){ + $query->field('id,title'); + } + ]) + ->page($page,$limit) + ->select(); + return compact('count','list'); } /** @@ -102,21 +111,19 @@ class StoreCouponUserRepository extends BaseRepository return compact('count', 'list'); } - public function writeOff(array $data) - { + public function writeOff(array $data,int $uid){ if(is_null($data['write_code'])) throw new ValidateException('核销码不存在'); $coupon = $this->dao->getWhere($data); - if (!$coupon) throw new ValidateException('核销码不存在'); - if ($coupon['status']) throw new ValidateException('已核销,请勿重复操作'); + if (!$coupon) throw new ValidateException('卡券不存在'); + if ($coupon['status'] == 1) throw new ValidateException('已核销,请勿重复操作'); $coupon->status = 1; $coupon->use_time = date('Y-m-d H:i:s'); $coupon->is_fail = 1; $StoreCouponOffRepository = app()->make(StoreCouponOffRepository::class); - //查询核销权限 - $StoreCouponOffRepository->validateWriteOff(); + $StoreCouponOffRepository->validateWriteOff($coupon, $uid); Db::transaction(function () use ($coupon, $StoreCouponOffRepository) { $coupon->save(); diff --git a/app/common/repositories/store/service/StoreServiceRepository.php b/app/common/repositories/store/service/StoreServiceRepository.php index ac7ea7c..7c8dc49 100644 --- a/app/common/repositories/store/service/StoreServiceRepository.php +++ b/app/common/repositories/store/service/StoreServiceRepository.php @@ -8,7 +8,9 @@ namespace app\common\repositories\store\service; use app\common\dao\store\service\StoreServiceDao; use app\common\model\store\service\StoreService; +use app\common\model\system\merchant\Merchant; use app\common\repositories\BaseRepository; +use app\common\repositories\system\merchant\MerchantRepository; use crmeb\exceptions\AuthException; use crmeb\services\JwtTokenService; use FormBuilder\Exception\FormBuilderException; @@ -77,31 +79,47 @@ class StoreServiceRepository extends BaseRepository } $adminRule = $filed = []; if($merId){ - $adminRule = [ - Elm::switches('status', '客服状态', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), - Elm::switches('customer', '订单管理', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), - Elm::switches('is_goods', '商品管理', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), - Elm::switches('is_verify', '开启核销', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), - Elm::switches('is_user', '客户管理', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), - Elm::switches('staff_manage', '员工管理', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), - Elm::switches('qr_code_show', '推广二维码', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), - Elm::switches('notify', '订单通知', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8)->control([ - [ - 'value' => 1, - 'rule' => [ - Elm::input('phone', '通知电话') + $merchantType = (int)app()->make(MerchantRepository::class)->getSearch(['mer_id'=>$merId])->value('merchant_type'); + if($merchantType == 0){ + $adminRule = [ + Elm::switches('status', '客服状态', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), + Elm::switches('customer', '订单管理', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), + Elm::switches('is_goods', '商品管理', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), + Elm::switches('is_verify', '开启核销', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), + Elm::switches('is_user', '客户管理', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), + Elm::switches('staff_manage', '员工管理', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), + Elm::switches('qr_code_show', '推广二维码', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), + Elm::switches('notify', '订单通知', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8)->control([ + [ + 'value' => 1, + 'rule' => [ + Elm::input('phone', '通知电话') + ] ] + ]) + ]; + $filed = [ + "value" => 1, + "rule" => [ + "status","customer","is_goods","is_verify","notify",'phone',"is_user","staff_manage",'qr_code_show' ] - ]) - - ]; + ]; + }else if($merchantType == 1){ + $adminRule = [ + Elm::switches('is_verify', '核销权限', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), + ]; + $filed = [ + "value" => 1, + "rule" => [ + "is_verify" + ] + ]; + }else if($merchantType == 2){ + $adminRule = []; + $filed = [ ]; + } } - $filed = [ - "value" => 1, - "rule" => [ - "status","customer","is_goods","is_verify","notify",'phone',"is_user","staff_manage",'qr_code_show' - ] - ]; + $adminRule[] = Elm::number('sort', '排序', 0)->precision(0)->max(99999); $prefix = $merId ? config('admin.merchant_prefix') : config('admin.admin_prefix'); return Elm::createForm(Route::buildUrl('merchantServiceCreate')->build(), array_merge([ @@ -165,7 +183,7 @@ class StoreServiceRepository extends BaseRepository $where['uid'] = $uid; $list = $this->dao->getSearch([]) ->hasWhere('merchant',function($query){ - $query->where('is_del', 0); + $query->where('is_del', 0)->where('merchant_type', 0); }) ->where('StoreService.is_del',0) ->where('StoreService.mer_id',$is_sys == 1 ? '=' : '>',0) diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index cb22f24..1fc5c7b 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -116,6 +116,13 @@ class Merchant extends BaseController // 参数获取 $merId = $this->request->param('mer_id'); if((int)$merId > 0){ + // 判断:当前商户是否绑定酒道馆 + $bindShopCount = (int)$this->repository->getSearch([]) + ->where('shop_mer_id', $merId) + ->where('is_del', 0) + ->count(); + if($bindShopCount <= 0) return app('json')->fail('未关联酒道馆!'); + // 生成推广码 $qrcode = $this->repository->createQrCode(['mid'=>$merId,'suid'=>$this->request->uid()]); return app('json')->success(['qr_code' => $qrcode]); diff --git a/app/controller/api/store/product/StoreCoupon.php b/app/controller/api/store/product/StoreCoupon.php index df70ae1..f43393a 100644 --- a/app/controller/api/store/product/StoreCoupon.php +++ b/app/controller/api/store/product/StoreCoupon.php @@ -154,8 +154,8 @@ class StoreCoupon extends BaseController public function writeOff(StoreCouponUserRepository $repository) { - $data = $this->request->param(); - $repository->writeOff($data); + $data = $this->request->params(['write_code']); + $repository->writeOff($data, $this->request->uid()); return app('json')->success('订单核销成功'); } diff --git a/app/controller/api/user/Exchange.php b/app/controller/api/user/Exchange.php index fff6f14..4d7c908 100644 --- a/app/controller/api/user/Exchange.php +++ b/app/controller/api/user/Exchange.php @@ -11,6 +11,7 @@ use app\common\model\user\User; use app\common\repositories\store\order\StoreOrderCreateRepository; use app\common\repositories\store\order\StoreOrderRepository; use app\common\repositories\store\service\StoreServiceRepository; +use app\common\repositories\system\merchant\MerchantRepository; use app\common\repositories\user\ExchangeIntegralRecordRepository; use app\common\repositories\user\ExchangePickupPointRepository; use app\common\repositories\user\ExchangePickupRecordRepository; @@ -494,8 +495,23 @@ class Exchange extends BaseController{ return app('json')->fail($e->getMessage()); } } + /** + * Common: 根据商户id 获取绑定的酒道馆 + * Author: wu-hui + * Time: 2024/02/05 9:36 + * @param $merId + * @return mixed + */ + public function merBindShop($merId){ + $bindShop = app()->make(MerchantRepository::class)->getSearch([]) + ->where('shop_mer_id', $merId) + ->where('is_del', 0) + ->findOrEmpty() + ->toArray(); + return app('json')->success($bindShop); + } diff --git a/app/listener/giveCoupon/CardOpeningEvent.php b/app/listener/giveCoupon/CardOpeningEvent.php index c3be53b..b6b66b1 100644 --- a/app/listener/giveCoupon/CardOpeningEvent.php +++ b/app/listener/giveCoupon/CardOpeningEvent.php @@ -19,7 +19,7 @@ class CardOpeningEvent $StoreCouponRepository = app()->make(StoreCouponRepository::class); foreach ($coupon as $val){ - $StoreCouponRepository->receiveSvipCounpon($val, $order['uid']); + $StoreCouponRepository->buyMembershipCardGive($val, $order); } } diff --git a/app/validate/merchant/StoreServiceValidate.php b/app/validate/merchant/StoreServiceValidate.php index e773d13..4817a1c 100644 --- a/app/validate/merchant/StoreServiceValidate.php +++ b/app/validate/merchant/StoreServiceValidate.php @@ -21,12 +21,12 @@ class StoreServiceValidate extends Validate 'pwd|员工密码' => 'require|min:6|max:16', 'confirm_pwd|确认密码' => 'require|min:6|max:16', 'is_open|状态' => 'require|in:0,1', - 'status|状态' => 'require|in:0,1', - 'is_verify|核销状态' => 'require|in:0,1', - 'is_goods|商品管理状态' => 'require|in:0,1', - 'notify|订单通知状态' => 'require|in:0,1', + // 'status|状态' => 'require|in:0,1', + // 'is_verify|核销状态' => 'require|in:0,1', + // 'is_goods|商品管理状态' => 'require|in:0,1', + // 'notify|订单通知状态' => 'require|in:0,1', 'sort|排序' => 'require|integer', - 'customer|展示统计管理状态' => 'require|in:0,1', + // 'customer|展示统计管理状态' => 'require|in:0,1', ]; protected $message = [ diff --git a/crmeb/listens/AutoCancelGroupOrderListen.php b/crmeb/listens/AutoCancelGroupOrderListen.php index 0f912ae..3da9c67 100644 --- a/crmeb/listens/AutoCancelGroupOrderListen.php +++ b/crmeb/listens/AutoCancelGroupOrderListen.php @@ -27,7 +27,7 @@ class AutoCancelGroupOrderListen extends TimerService implements ListenerInterfa try { $storeGroupOrderRepository->cancel($id); } catch (\Exception $e) { - Log::info('自动关闭订单失败' . var_export($id, 1)); + // Log::info('自动关闭订单失败' . var_export($id, 1)); } } }); diff --git a/route/api.php b/route/api.php index 33be2f1..6c3b79c 100644 --- a/route/api.php +++ b/route/api.php @@ -366,6 +366,8 @@ Route::group('api/', function () { Route::get('record_integral_list', 'Exchange/recordIntegralList'); // 转赠 Route::get('quota_transfer', 'Exchange/quotaTransfer'); + // 获取 商户绑定的酒道馆信息 + Route::get('mer_bind_shop/:merId', 'Exchange/merBindShop'); })->prefix('api.user.');