核销券功能的接口

This commit is contained in:
zpian 2024-02-01 18:53:59 +08:00
parent 8d34485be2
commit 554febf41f
5 changed files with 79 additions and 8 deletions

View File

@ -9,6 +9,7 @@ namespace app\common\repositories\store\coupon;
use app\common\dao\store\coupon\StoreCouponDao;
use app\common\dao\store\coupon\StoreCouponProductDao;
use app\common\model\store\coupon\StoreCoupon;
use app\common\repositories\store\coupon\StoreCouponUserRepository;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\product\ProductRepository;
use app\common\repositories\store\StoreCategoryRepository;
@ -325,7 +326,8 @@ class StoreCouponRepository extends BaseRepository
'use_min_price' => $coupon['use_min_price'],
'type' => $type,
'coupon_id' => $coupon['coupon_id'],
'mer_id' => $coupon['mer_id']
'mer_id' => $coupon['mer_id'],
'write_code' => $this->writeCodeCreate(),
];
if ($coupon['send_type'] == self::GET_COUPON_TYPE_SVIP) {
$data['start_time'] = date('Y-m-d 00:00:00',time());
@ -662,4 +664,20 @@ class StoreCouponRepository extends BaseRepository
}
}
public function writeCodeCreate(string $code = '')
{
$code = $code ?: $this->codeCreate();
if(app()->make(StoreCouponUserRepository::class)->getSearch(['write_code'=>$code])->field('write_code')->find()){
$this->writeCodeCreate($this->codeCreate());
}
return $code;
}
private function codeCreate()
{
$randomString = uniqid(); // 获取当前时间相关的随机字符串
$md5HashedString = md5($randomString); // MD5加密字符串
return substr($md5HashedString, 0, 12); // 提取前12位作为最终结果
}
}

View File

@ -11,6 +11,8 @@ use app\common\repositories\BaseRepository;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\exception\ValidateException;
use think\facade\Db;
/**
* Class StoreCouponUserRepository
@ -100,4 +102,31 @@ class StoreCouponUserRepository extends BaseRepository
return compact('count', 'list');
}
public function writeOff(array $data)
{
$coupon = $this->dao->getWhere($data);
if (!$coupon) throw new ValidateException('核销码不存在');
if ($coupon['status']) throw new ValidateException('已核销,请勿重复操作');
$coupon->status = 1;
$coupon->use_time = date('Y-m-d H:i:s');
//订单记录
$storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
// Db::transaction(function () use ($coupon,$storeOrderStatusRepository,$serviceId) {
// $coupon->save();
// $orderStatus = [
// 'order_id' => $order->order_id,
// 'order_sn' => $order->order_sn,
// 'type' => $storeOrderStatusRepository::TYPE_ORDER,
// 'change_message' => '订单已核销',
// 'change_type' => $storeOrderStatusRepository::ORDER_STATUS_TAKE,
// ];
// if ($serviceId){
// $storeOrderStatusRepository->createServiceLog($serviceId,$orderStatus);
// } else {
// $storeOrderStatusRepository->createAdminLog($orderStatus);
// }
// });
// event('order.verify', compact('order'));
}
}

View File

@ -9,6 +9,7 @@ namespace app\controller\api\store\product;
use app\common\repositories\store\coupon\StoreCouponProductRepository;
use app\common\repositories\store\coupon\StoreCouponRepository;
use app\common\repositories\store\coupon\StoreCouponUserRepository;
use crmeb\services\QrcodeService;
use crmeb\basic\BaseController;
use think\App;
use think\db\exception\DataNotFoundException;
@ -142,4 +143,26 @@ class StoreCoupon extends BaseController
return app('json')->success($coupons);
}
public function createQRcode()
{
$write_code = $this->request->param('write_code');
$valueData = 'write_code='.$write_code;
// $path = 'pages/user/write_off';
$path = 'pages/index/index';
$qrcode = app()->make(QrcodeService::class)->createQrCode($valueData,$path);
return app('json')->success(['qr_code' => $qrcode]);
}
public function writeOff(StoreCouponUserRepository $repository)
{
$data = $this->request->param();
$result = $repository->writeOff($data);
if(!$result){
return app('json')->erorr('该商家没有核销权限');
}
// return app('json')->success(['qr_code' => $qrcode]);
}
}

View File

@ -1,4 +1,4 @@
<?php
<?php

View File

@ -385,10 +385,10 @@ Route::group('api/', function () {
// 代理中心相关
Route::group('agent', function () {
Route::get('agent_list', 'agentList');// 我的代理身份列表
Route::get('qr_code_invite_supplier', 'qrCodeInviteSupplier');// 供应商邀请二维码
Route::get('qr_code_invite', 'qrCodeInviteSupplier');// 供应商邀请二维码
Route::get('single_agent_info/:id', 'singleAgentInfo');// 获取单个代理人员信息
Route::get('get_config', 'getConfig');// 获取配置信息
Route::post('agent_apply', 'apply');// 提交申请信息
@ -397,9 +397,8 @@ Route::group('api/', function () {
// 供应商相关
Route::group('supplier', function () {
Route::post('apply', 'applyJoin');// 申请成为供应商
Route::post('apply_record', 'applyRecord');// 申请记录
Route::get('apply_info', 'applyInfo');// 申请信息详情
@ -535,6 +534,8 @@ Route::group('api/', function () {
Route::get('list', 'api.store.product.StoreCoupon/lst');
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');
});
//商户