修改:优惠券赠送及核销流程修改
This commit is contained in:
parent
d53848036a
commit
92076147f8
|
|
@ -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');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
|
|
|
|||
|
|
@ -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('订单核销成功');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class CardOpeningEvent
|
|||
|
||||
$StoreCouponRepository = app()->make(StoreCouponRepository::class);
|
||||
foreach ($coupon as $val){
|
||||
$StoreCouponRepository->receiveSvipCounpon($val, $order['uid']);
|
||||
$StoreCouponRepository->buyMembershipCardGive($val, $order);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 = [
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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.');
|
||||
|
|
|
|||
Loading…
Reference in New Issue