| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace addons\HiGo\common\global_func;
- use addons\HiGo\common\enums\HiGoEnum;
- use addons\HiGo\common\logic\HiBeiLogic;
- use addons\HiGo\common\models\HigoWallet;
- use addons\Mch\common\models\Mch;
- use addons\Store\common\models\Store;
- use common\enums\StatusEnum;
- use common\models\user\UserWallet;
- use Yii;
- class OrderCheck
- {
- /**
- * 检测商家订单嗨呗数量是否充足
- * @param $params
- * @return array
- */
- public function getNeedHiBei($params)
- {
- $return = [
- 'status' => true,
- 'msg' => 'success'
- ];
- try{
- $mall_id = $params['mall_id'];
- $store_id = $params['store_id'] ?? 0;
- $mch_id = $params['mch_id'] ?? 0;
- //todo 修改验证门店是否参与嗨购
- if(!$store_id && !$mch_id) throw new \Exception('非商家订单');
- $pay_money = $params['pay_money'] ?? 0;
- $setting = \Yii::$app->services->setting->addons->get($mall_id, HiGoEnum::ADDONS_NAME, 'basic');
- if (empty($setting['merchant_buy_goods'])) throw new \Exception('未开启商家嗨购商品');
- if(empty($setting['is_order_settings'])) throw new \Exception('下单设置');
- //嗨呗当前价值
- $now_price = HiBeiLogic::getNowPrice($mall_id);
- if (bccomp($now_price, 0, 10) <= 0) {
- throw new \Exception('嗨呗当前价格异常');
- }
- //商家让利部分
- $profit = bcmul($pay_money,$setting['merchant_profit_multiple']/100,10);
- $hi_bei_num = bcdiv($profit,$now_price,10);
- //获取商家当前嗨呗数量
- if($store_id > 0 ){
- $store = Store::findOne(['mall_id' => $mall_id, 'id' => $store_id, 'status' => StatusEnum::ENABLED]);
- $mch_user_id = $store['user_id'];
- }else{
- $mch = Mch::findOne(['mall_id' => $mall_id, 'id' => $mch_id, 'status' => StatusEnum::ENABLED]);
- $mch_user_id = $mch['user_id'];
- }
- if(!$mch_user_id) throw new \Exception('查询不到该商家');
- $wallet = HigoWallet::findOne(['mall_id' => $mall_id,'user_id' => $mch_user_id,'status' => StatusEnum::ENABLED]);
- if(!$wallet || bccomp($wallet->hi_bei,$hi_bei_num,10) < 0){
- $return['status'] = false;
- $return['msg'] = $setting['buy_product_prompt'] ?? '商家嗨呗不足';
- }
- }catch(\Exception $e){
- Yii::error('getNeedHiBei error:'.$e->getMessage());
- }
- return $return;
- }
- }
|