parent
3e32334381
commit
ec592a966f
|
|
@ -20,4 +20,43 @@ class StoreCouponOffDao extends BaseDao
|
|||
{
|
||||
return StoreCouponOff::class;
|
||||
}
|
||||
/**
|
||||
* Common: 核销记录查询
|
||||
* Author: wu-hui
|
||||
* Time: 2024/03/28 11:29
|
||||
* @param array $params
|
||||
* @return StoreCouponOff
|
||||
*/
|
||||
public function searchList(array $params){
|
||||
return (new StoreCouponOff())
|
||||
->when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){
|
||||
$query->where('id', (int)$params['id']);
|
||||
})
|
||||
->when(isset($params['uid']) && $params['uid'] !== '',function($query) use ($params){
|
||||
$query->where('uid', (int)$params['uid']);
|
||||
})
|
||||
->when(isset($params['write_off_mer_id']) && $params['write_off_mer_id'] !== '',function($query) use ($params){
|
||||
$query->where('write_off_mer_id', (int)$params['write_off_mer_id']);
|
||||
})
|
||||
->with([
|
||||
'user' => function($query){
|
||||
$query->field('uid,nickname,avatar');
|
||||
},
|
||||
'coupon' => function($query){
|
||||
$query->field('coupon_id,type,send_type');
|
||||
},
|
||||
'couponUser' => function($query){
|
||||
$query->field('coupon_user_id,write_code,brand_id')->with([
|
||||
'brand' => function($query){
|
||||
$query->field('id,title')->bind(['title']);
|
||||
}
|
||||
]);
|
||||
}
|
||||
])
|
||||
->order('create_time DESC,id DESC');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ class MerchantCheckBaseInfoMiddleware extends BaseMiddleware
|
|||
if ($cache->has($key)) return;
|
||||
|
||||
|
||||
if (!$merchant->mer_avatar || !$merchant->mer_banner || !$merchant->mer_info || !$merchant->mer_address) {
|
||||
throw new ValidateException('您好,请前往左侧菜单【设置】-【商户基本信息】完善商户基本信息。');
|
||||
}
|
||||
// if (!$merchant->mer_avatar || !$merchant->mer_banner || !$merchant->mer_info || !$merchant->mer_address) {
|
||||
// throw new ValidateException('您好,请前往左侧菜单【设置】-【商户基本信息】完善商户基本信息。');
|
||||
// }
|
||||
Cache::store('file')->set('mer_valid_' . $merchant->mer_id, 1, 3600 * 8);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,4 +58,9 @@ class StoreCouponOff extends BaseModel
|
|||
{
|
||||
return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
|
||||
}
|
||||
|
||||
|
||||
public function couponUser(){
|
||||
return $this->hasOne(StoreCouponUser::class, 'write_code', 'write_code');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,10 +35,30 @@ class StoreCouponOffRepository extends BaseRepository
|
|||
$this->dao = $dao;
|
||||
}
|
||||
|
||||
public function createData(array $data)
|
||||
{
|
||||
public function createData(array $data){
|
||||
return $this->dao->create($data);
|
||||
}
|
||||
/**
|
||||
* Common: 获取核销记录
|
||||
* Author: wu-hui
|
||||
* Time: 2024/03/28 11:30
|
||||
* @param array $where
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getList(array $where, int $page,int $limit){
|
||||
$query = $this->dao->searchList((array)$where);
|
||||
$count = $query->count();
|
||||
$list = $query->page($page, $limit)->select();
|
||||
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Common: 判断:当前用户是否有核销权限
|
||||
* Author: wu-hui
|
||||
|
|
|
|||
|
|
@ -110,12 +110,13 @@ class StoreCouponUserRepository extends BaseRepository
|
|||
$list = $query->page($page, $limit)->select();
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
// 提货券 - 核销
|
||||
public function writeOff(array $data,int $uid){
|
||||
if(is_null($data['write_code'])) throw new ValidateException('核销码不存在');
|
||||
$coupon = $this->dao->getWhere($data);
|
||||
$coupon = $this->dao->getWhere(['write_code'=>$data['write_code']]);
|
||||
if (!$coupon) throw new ValidateException('卡券不存在');
|
||||
if ($coupon['status'] == 1) throw new ValidateException('已核销,请勿重复操作');
|
||||
if ($coupon['status'] == 2) throw new ValidateException('已过期!');
|
||||
|
||||
$coupon->status = 1;
|
||||
$coupon->use_time = date('Y-m-d H:i:s');
|
||||
|
|
@ -125,18 +126,20 @@ class StoreCouponUserRepository extends BaseRepository
|
|||
//查询核销权限
|
||||
$StoreCouponOffRepository->validateWriteOff($coupon, $uid);
|
||||
|
||||
Db::transaction(function () use ($coupon, $StoreCouponOffRepository) {
|
||||
Db::transaction(function () use ($coupon, $StoreCouponOffRepository, $data) {
|
||||
$coupon->save();
|
||||
$array = [
|
||||
'mer_id' => $coupon->mer_id,
|
||||
'coupon_id' => $coupon->coupon_id,
|
||||
'coupon_title' => $coupon->coupon_title,
|
||||
'uid' => $coupon->uid,
|
||||
'write_code' => $coupon->write_code,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'mer_id' => $coupon->mer_id,
|
||||
'coupon_id' => $coupon->coupon_id,
|
||||
'coupon_title' => $coupon->coupon_title,
|
||||
'uid' => $coupon->uid,
|
||||
'write_code' => $coupon->write_code,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'write_off_mer_id' => $data['mer_id'],
|
||||
];
|
||||
|
||||
$StoreCouponOffRepository->createData($array);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,8 @@ class StoreServiceRepository extends BaseRepository
|
|||
"is_verify",'product_exchange','purchase_permission'
|
||||
]
|
||||
];
|
||||
}else if($merchantType == 2){
|
||||
}
|
||||
else if($merchantType == 2){
|
||||
$adminRule = [];
|
||||
$filed = [
|
||||
"value" => 1,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
namespace app\controller\api\store\product;
|
||||
|
||||
|
||||
use app\common\repositories\store\coupon\StoreCouponOffRepository;
|
||||
use app\common\repositories\store\coupon\StoreCouponProductRepository;
|
||||
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
use app\common\repositories\store\coupon\StoreCouponUserRepository;
|
||||
|
|
@ -142,7 +143,7 @@ class StoreCoupon extends BaseController
|
|||
}
|
||||
return app('json')->success($coupons);
|
||||
}
|
||||
|
||||
// 提货券 - 生成核销二维码
|
||||
public function createQRcode()
|
||||
{
|
||||
$write_code = $this->request->param('write_code');
|
||||
|
|
@ -151,12 +152,30 @@ class StoreCoupon extends BaseController
|
|||
$qrcode = app()->make(QrcodeService::class)->createQrCode($valueData,$path);
|
||||
return app('json')->success(['qr_code' => $qrcode]);
|
||||
}
|
||||
|
||||
public function writeOff(StoreCouponUserRepository $repository)
|
||||
{
|
||||
$data = $this->request->params(['write_code']);
|
||||
// 提货券 - 核销
|
||||
public function writeOff(StoreCouponUserRepository $repository){
|
||||
$data = $this->request->params(['write_code','mer_id']);
|
||||
$repository->writeOff($data, $this->request->uid());
|
||||
return app('json')->success('订单核销成功');
|
||||
return app('json')->success('核销成功');
|
||||
}
|
||||
// 提货券 - 核销记录
|
||||
public function writeOffRecord(StoreCouponUserRepository $repository){
|
||||
$merId = $this->request->param('mer_id', -1);
|
||||
[$page, $limit] = $this->getPage();
|
||||
|
||||
$data = app()->make(StoreCouponOffRepository::class)->getList(['write_off_mer_id' => $merId], (int)$page, (int)$limit);
|
||||
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -576,7 +576,11 @@ Route::group('api/', function () {
|
|||
Route::get('getlst', 'api.store.product.StoreCoupon/getList');
|
||||
Route::get('new_people', 'api.store.product.StoreCoupon/newPeople');
|
||||
Route::get('create_qrcode', 'api.store.product.StoreCoupon/createQRcode');
|
||||
// 提货券相关
|
||||
Route::post('write_off', 'api.store.product.StoreCoupon/writeOff');
|
||||
Route::get('write_off_record', 'api.store.product.StoreCoupon/writeOffRecord');
|
||||
|
||||
|
||||
});
|
||||
|
||||
//商户
|
||||
|
|
|
|||
Loading…
Reference in New Issue