核销券功能的接口
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)
|
||||
{
|
||||
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('已核销,请勿重复操作');
|
||||
|
||||
$coupon->status = 1;
|
||||
$coupon->use_time = date('Y-m-d H:i:s');
|
||||
$coupon->is_fail = 1;
|
||||
|
||||
//订单记录
|
||||
$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'));
|
||||
$StoreCouponOffRepository = app()->make(StoreCouponOffRepository::class);
|
||||
|
||||
//查询核销权限
|
||||
$StoreCouponOffRepository->validateWriteOff();
|
||||
|
||||
Db::transaction(function () use ($coupon, $StoreCouponOffRepository) {
|
||||
$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'),
|
||||
];
|
||||
|
||||
$StoreCouponOffRepository->createData($array);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,8 +147,7 @@ class StoreCoupon extends BaseController
|
|||
{
|
||||
$write_code = $this->request->param('write_code');
|
||||
$valueData = 'write_code='.$write_code;
|
||||
// $path = 'pages/user/write_off';
|
||||
$path = 'pages/index/index';
|
||||
$path = 'pages/users/write_off/index';
|
||||
$qrcode = app()->make(QrcodeService::class)->createQrCode($valueData,$path);
|
||||
return app('json')->success(['qr_code' => $qrcode]);
|
||||
}
|
||||
|
|
@ -156,13 +155,8 @@ class StoreCoupon extends BaseController
|
|||
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]);
|
||||
$repository->writeOff($data);
|
||||
return app('json')->success('订单核销成功');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue