调整商户补贴进度查询
This commit is contained in:
parent
da72fe2d5b
commit
6c4ce77c83
@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\controller\api\server;
|
||||
|
||||
use app\common\model\store\consumption\StoreConsumption;
|
||||
use app\common\model\store\consumption\StoreConsumptionUser;
|
||||
use app\common\model\system\merchant\FinancialRecord;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
@ -65,15 +66,76 @@ class Store extends BaseController
|
||||
return app('json')->success(['count' => $count, 'list' => $list]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 补贴进度查询
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function subsidy()
|
||||
{
|
||||
$type = $this->request->get('type', 1);
|
||||
$saleAmount = Merchant::where('mer_id', $this->merId)->value('sale_amount');
|
||||
$uid = $this->request->uid();
|
||||
$merchant = Merchant::where('mer_id', $this->merId)->field('sale_amount,purchase_amount,type_id')->find()->toArray();
|
||||
$saleTarget = '0.00';
|
||||
$purchaseTarget = '0.00';
|
||||
if ($type == 1) {
|
||||
$purchaseAmount = StoreConsumptionUser::where('uid')
|
||||
->where('')
|
||||
->column('coupon_price,balance');
|
||||
//春耕采购补贴
|
||||
$couponId = StoreConsumption::where('type', StoreConsumption::TYPE_PULL_CONSUMPTION)->value('coupon_id');
|
||||
$userConsumption = StoreConsumptionUser::where('uid', $uid)
|
||||
->where('coupon_id', $couponId)
|
||||
->where('status', '<>', -1)
|
||||
->field('coupon_price,balance')
|
||||
->find();
|
||||
if (!empty($userConsumption)) {
|
||||
$couponId = StoreConsumption::where('type', StoreConsumption::TYPE_RECHARGE)->value('coupon_id');
|
||||
$subsidyAmount = StoreConsumptionUser::where('uid', $uid)
|
||||
->where('coupon_id', $couponId)
|
||||
->value('coupon_price');
|
||||
$saleTarget = $userConsumption['coupon_price'];
|
||||
$purchaseTarget = $userConsumption['coupon_price'];
|
||||
$merchant['purchase_amount'] = bcsub($userConsumption['coupon_price'], $userConsumption['balance'], 2);
|
||||
}
|
||||
} else {
|
||||
//增收销售补贴
|
||||
$consumption = StoreConsumption::where('type', StoreConsumption::TYPE_SALE_SUBSIDY)->find();
|
||||
if ($consumption) {
|
||||
$userConsumption = StoreConsumptionUser::where('uid', $uid)
|
||||
->where('coupon_id', $consumption['coupon_id'])
|
||||
->where('status', '<>', -1)
|
||||
->field('coupon_price,balance,status')
|
||||
->find();
|
||||
$subsidyAmount = $userConsumption['coupon_price'] ?? '0.00';
|
||||
foreach ($consumption['config'] as $k => $item) {
|
||||
if (empty($userConsumption) && in_array($merchant['type_id'], $item['type_id'])) {
|
||||
$saleTarget = $item['amount'];
|
||||
$purchaseTarget = bcmul($saleTarget, 0.5, 2);
|
||||
break;
|
||||
}
|
||||
if (!empty($userConsumption) && in_array($merchant['type_id'], $item['type_id'])) {
|
||||
$nextItem = $consumption['config'][$k + 1] ?? $item;
|
||||
$saleTarget = $nextItem['amount'];
|
||||
$purchaseTarget = bcmul($saleTarget, 0.5, 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$saleFinishRate = $saleTarget <= 0 ? 0 : bcdiv($merchant['sale_amount'], $saleTarget, 2);
|
||||
$saleFinishRate = bcmul(min($saleFinishRate, 1), 100, 0);
|
||||
$purchaseFinishRate = $purchaseTarget <= 0 ? 0 : bcdiv($merchant['purchase_amount'], $purchaseTarget, 2);
|
||||
$purchaseFinishRate = bcmul(min($purchaseFinishRate, 1), 100, 0);
|
||||
return app('json')->success([
|
||||
'subsidy_amount' => empty($subsidyAmount) ? '0.00' : $subsidyAmount,
|
||||
'subsidy_status' => $saleFinishRate >= 100 && $purchaseFinishRate >= 100,
|
||||
'sale_target' => $saleTarget,
|
||||
'sale_amount' => $merchant['sale_amount'],
|
||||
'sale_finish_rate' => $saleFinishRate,
|
||||
'purchase_target' => $purchaseTarget,
|
||||
'purchase_amount' => $merchant['purchase_amount'],
|
||||
'purchase_finish_rate' => $purchaseFinishRate
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user