核销券功能的接口
This commit is contained in:
parent
477d21b481
commit
36d8f42664
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace app\common\dao\store\coupon;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\dao\BaseDao;
|
||||||
|
use app\common\model\BaseModel;
|
||||||
|
use app\common\model\store\coupon\StoreCouponOff;
|
||||||
|
|
||||||
|
class StoreCouponOffDao extends BaseDao
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return BaseModel
|
||||||
|
* @author xaboy
|
||||||
|
* @day 2020-03-30
|
||||||
|
*/
|
||||||
|
protected function getModel(): string
|
||||||
|
{
|
||||||
|
return StoreCouponOff::class;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace app\common\model\store\coupon;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\BaseModel;
|
||||||
|
use app\common\model\system\merchant\Merchant;
|
||||||
|
use app\common\model\user\User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class StoreCouponUser
|
||||||
|
* @package app\common\model\store\coupon
|
||||||
|
* @author xaboy
|
||||||
|
* @day 2020-05-14
|
||||||
|
*/
|
||||||
|
class StoreCouponOff extends BaseModel
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @author xaboy
|
||||||
|
* @day 2020-03-30
|
||||||
|
*/
|
||||||
|
public static function tablePk(): string
|
||||||
|
{
|
||||||
|
return 'id';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @author xaboy
|
||||||
|
* @day 2020-03-30
|
||||||
|
*/
|
||||||
|
public static function tableName(): string
|
||||||
|
{
|
||||||
|
return 'store_coupon_off';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->hasOne(User::class, 'uid', 'uid');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function coupon()
|
||||||
|
{
|
||||||
|
return $this->hasOne(StoreCoupon::class, 'coupon_id', 'coupon_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function product()
|
||||||
|
{
|
||||||
|
return $this->hasMany(StoreCouponProduct::class, 'coupon_id', 'coupon_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function merchant()
|
||||||
|
{
|
||||||
|
return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace app\common\repositories\store\coupon;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\dao\store\coupon\StoreCouponOffDao;
|
||||||
|
use app\common\repositories\BaseRepository;
|
||||||
|
use think\exception\ValidateException;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class StoreCouponUserRepository
|
||||||
|
* @package app\common\repositories\store\coupon
|
||||||
|
* @author xaboy
|
||||||
|
* @day 2020-05-14
|
||||||
|
* @mixin StoreCouponOffDao
|
||||||
|
*/
|
||||||
|
class StoreCouponOffRepository extends BaseRepository
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var StoreCouponOffDao
|
||||||
|
*/
|
||||||
|
protected $dao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StoreCouponUserRepository constructor.
|
||||||
|
* @param StoreCouponOffDao $dao
|
||||||
|
*/
|
||||||
|
public function __construct(StoreCouponOffDao $dao)
|
||||||
|
{
|
||||||
|
$this->dao = $dao;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createData(array $data)
|
||||||
|
{
|
||||||
|
return $this->dao->create($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateWriteOff(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -104,29 +104,32 @@ class StoreCouponUserRepository extends BaseRepository
|
||||||
|
|
||||||
public function writeOff(array $data)
|
public function writeOff(array $data)
|
||||||
{
|
{
|
||||||
|
if(is_null($data['write_code'])) throw new ValidateException('核销码不存在');
|
||||||
$coupon = $this->dao->getWhere($data);
|
$coupon = $this->dao->getWhere($data);
|
||||||
if (!$coupon) throw new ValidateException('核销码不存在');
|
if (!$coupon) throw new ValidateException('核销码不存在');
|
||||||
if ($coupon['status']) throw new ValidateException('已核销,请勿重复操作');
|
if ($coupon['status']) throw new ValidateException('已核销,请勿重复操作');
|
||||||
|
|
||||||
$coupon->status = 1;
|
$coupon->status = 1;
|
||||||
$coupon->use_time = date('Y-m-d H:i:s');
|
$coupon->use_time = date('Y-m-d H:i:s');
|
||||||
|
$coupon->is_fail = 1;
|
||||||
|
|
||||||
//订单记录
|
$StoreCouponOffRepository = app()->make(StoreCouponOffRepository::class);
|
||||||
$storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
|
|
||||||
// Db::transaction(function () use ($coupon,$storeOrderStatusRepository,$serviceId) {
|
//查询核销权限
|
||||||
// $coupon->save();
|
$StoreCouponOffRepository->validateWriteOff();
|
||||||
// $orderStatus = [
|
|
||||||
// 'order_id' => $order->order_id,
|
Db::transaction(function () use ($coupon, $StoreCouponOffRepository) {
|
||||||
// 'order_sn' => $order->order_sn,
|
$coupon->save();
|
||||||
// 'type' => $storeOrderStatusRepository::TYPE_ORDER,
|
$array = [
|
||||||
// 'change_message' => '订单已核销',
|
'mer_id' => $coupon->mer_id,
|
||||||
// 'change_type' => $storeOrderStatusRepository::ORDER_STATUS_TAKE,
|
'coupon_id' => $coupon->coupon_id,
|
||||||
// ];
|
'coupon_title' => $coupon->coupon_title,
|
||||||
// if ($serviceId){
|
'uid' => $coupon->uid,
|
||||||
// $storeOrderStatusRepository->createServiceLog($serviceId,$orderStatus);
|
'write_code' => $coupon->write_code,
|
||||||
// } else {
|
'create_time' => date('Y-m-d H:i:s'),
|
||||||
// $storeOrderStatusRepository->createAdminLog($orderStatus);
|
];
|
||||||
// }
|
|
||||||
// });
|
$StoreCouponOffRepository->createData($array);
|
||||||
// event('order.verify', compact('order'));
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,8 +147,7 @@ class StoreCoupon extends BaseController
|
||||||
{
|
{
|
||||||
$write_code = $this->request->param('write_code');
|
$write_code = $this->request->param('write_code');
|
||||||
$valueData = 'write_code='.$write_code;
|
$valueData = 'write_code='.$write_code;
|
||||||
// $path = 'pages/user/write_off';
|
$path = 'pages/users/write_off/index';
|
||||||
$path = 'pages/index/index';
|
|
||||||
$qrcode = app()->make(QrcodeService::class)->createQrCode($valueData,$path);
|
$qrcode = app()->make(QrcodeService::class)->createQrCode($valueData,$path);
|
||||||
return app('json')->success(['qr_code' => $qrcode]);
|
return app('json')->success(['qr_code' => $qrcode]);
|
||||||
}
|
}
|
||||||
|
|
@ -156,13 +155,8 @@ class StoreCoupon extends BaseController
|
||||||
public function writeOff(StoreCouponUserRepository $repository)
|
public function writeOff(StoreCouponUserRepository $repository)
|
||||||
{
|
{
|
||||||
$data = $this->request->param();
|
$data = $this->request->param();
|
||||||
$result = $repository->writeOff($data);
|
$repository->writeOff($data);
|
||||||
if(!$result){
|
return app('json')->success('订单核销成功');
|
||||||
return app('json')->erorr('该商家没有核销权限');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// return app('json')->success(['qr_code' => $qrcode]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue