调整补贴发放
This commit is contained in:
parent
a9d9212db7
commit
4f0d5b2dd9
@ -55,6 +55,8 @@ class StoreCouponUserDao extends BaseDao
|
||||
public $couponUsed;
|
||||
/** @var float $profitRate 商品毛利率 */
|
||||
public $profitRate;
|
||||
public $updateOrigin = false; //是否更新优惠券初始金额
|
||||
public $insertDetail = true; //是否写入明细
|
||||
|
||||
const RATE_ARRAY = [
|
||||
['profit_rate' => 10, 'use_rate' => 0.1],
|
||||
@ -182,14 +184,19 @@ class StoreCouponUserDao extends BaseDao
|
||||
throw new ValidateException('优惠券不存在');
|
||||
}
|
||||
$storeCouponUser->coupon_price = bcadd($storeCouponUser->coupon_price, $amount, 2);
|
||||
if ($this->updateOrigin) {
|
||||
$storeCouponUser->origin_price = bcadd($storeCouponUser->origin_price, $amount, 2);
|
||||
}
|
||||
if ($storeCouponUser->status != 0 && $storeCouponUser->coupon_price > 0) {
|
||||
$storeCouponUser->status = 0;
|
||||
}
|
||||
if (!$storeCouponUser->save()) {
|
||||
throw new ValidateException('优惠券余额更新出错');
|
||||
}
|
||||
$coupon = ['coupon_id' => $storeCouponUser['coupon_id'], 'coupon_price' => $amount];
|
||||
StoreCouponDetail::income($order, $storeCouponUser['coupon_user_id'], $coupon, $mark, StoreCouponDetail::STATUS_VALID, StoreCouponDetail::SEND_FINISHED);
|
||||
if ($this->insertDetail) {
|
||||
$coupon = ['coupon_id' => $storeCouponUser['coupon_id'], 'coupon_price' => $amount];
|
||||
StoreCouponDetail::income($order, $storeCouponUser['coupon_user_id'], $coupon, $mark, StoreCouponDetail::STATUS_VALID, StoreCouponDetail::SEND_FINISHED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\controller\api\server;
|
||||
|
||||
use app\common\dao\store\coupon\StoreCouponUserDao;
|
||||
use app\common\model\store\coupon\StoreCoupon;
|
||||
use app\common\model\store\coupon\StoreCouponDetail;
|
||||
use app\common\model\store\coupon\StoreCouponUser;
|
||||
@ -12,6 +13,7 @@ use app\controller\api\Common;
|
||||
use crmeb\basic\BaseController;
|
||||
use think\App;
|
||||
use think\db\Query;
|
||||
use think\facade\Db;
|
||||
|
||||
class Store extends BaseController
|
||||
{
|
||||
@ -203,4 +205,38 @@ class Store extends BaseController
|
||||
return app('json')->success($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取补贴
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function receive($id)
|
||||
{
|
||||
$userId = $this->request->uid();
|
||||
$couponDetail = StoreCouponDetail::where('id', $id)->where('uid', $userId)->find();
|
||||
if (empty($couponDetail) || $couponDetail['send_status'] != StoreCouponDetail::SEND_CONFIRM) {
|
||||
return app('json')->fail('当前状态不支持操作');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$couponDetail->send_status = StoreCouponDetail::SEND_FINISHED;
|
||||
if (!$couponDetail->save()) {
|
||||
throw new \Exception('优惠券详情保存出错');
|
||||
}
|
||||
/** @var StoreCouponUserDao $couponDao */
|
||||
$couponDao = app()->make(StoreCouponUserDao::class);
|
||||
$couponDao->updateOrigin = true;
|
||||
$couponDao->insertDetail = false;
|
||||
$couponDao->increase($couponDetail['coupon_user_id'], $couponDetail['amount'], []);
|
||||
Db::commit();
|
||||
return app('json')->success('领取成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return app('json')->fail('领取出错,请稍后重试');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,11 @@ Route::group(function () {
|
||||
'_auth' => false,
|
||||
'_form' => 'userSubsidyStatus',
|
||||
]);
|
||||
Route::post('update', '/update')->name('userSubsidyUpdate')->option([
|
||||
'_alias' => '修改补贴金额',
|
||||
'_auth' => false,
|
||||
'_form' => 'userSubsidyUpdate',
|
||||
]);
|
||||
})->prefix('admin.system.financial.Subsidy')->option([
|
||||
'_path' => '/cms/userSubsidy',
|
||||
'_auth' => true,
|
||||
|
@ -315,6 +315,7 @@ Route::group('api/', function () {
|
||||
Route::get('attr/list', 'StoreProductAttrTemplate/getlist');
|
||||
Route::get('subsidy', 'Store/subsidy');
|
||||
Route::get('subsidyRecord', 'Store/subsidyRecord');
|
||||
Route::get('subsidyReceive', 'Store/receive');
|
||||
})->prefix('api.server.')->middleware(\app\common\middleware\MerchantServerMiddleware::class, 1);
|
||||
|
||||
//管理员订单
|
||||
|
Loading…
x
Reference in New Issue
Block a user