|
|
@@ -19,6 +19,8 @@ use common\models\Region;
|
|
|
use common\models\ShopGoods;
|
|
|
use common\models\User;
|
|
|
use common\models\UserNetwork;
|
|
|
+use common\models\RemainPv;
|
|
|
+use common\models\FlowRemainPv;
|
|
|
use yii\base\Exception;
|
|
|
|
|
|
/**
|
|
|
@@ -57,6 +59,8 @@ class OrderForm extends Model
|
|
|
private $_standardAmount;
|
|
|
private $_decAmountStandard;
|
|
|
private $_exchangeRate;
|
|
|
+ private $_remainPv;
|
|
|
+ private $_realPv;
|
|
|
|
|
|
/**
|
|
|
* @var Order
|
|
|
@@ -88,25 +92,25 @@ class OrderForm extends Model
|
|
|
public function attributeLabels()
|
|
|
{
|
|
|
return [
|
|
|
- 'sn' => '订单号',
|
|
|
+ 'sn' => 'Order Code', // 订单号
|
|
|
'expressCompany' => '快递公司',
|
|
|
'orderTrackNo' => '快递单号',
|
|
|
- 'status' => '状态',
|
|
|
- 'remark' => '备注',
|
|
|
- 'type' => '订单类型',
|
|
|
+ 'status' => 'State', // 状态
|
|
|
+ 'remark' => 'Remark', // 备注
|
|
|
+ 'type' => 'Order Type',// 订单类型
|
|
|
'addressId' => 'Shipping address',// 收货地址
|
|
|
- 'payType' => '支付方式',
|
|
|
- 'goodsId' => 'product ID',//商品ID
|
|
|
+ 'payType' => 'Pay Type',// 支付方式
|
|
|
+ 'goodsId' => 'Product ID',//商品ID
|
|
|
'goodsNum' => 'Product quantity',//商品数量
|
|
|
'userName' => 'Repeat sales Member No. does not exist',//复消会员编号
|
|
|
- 'consignee' => '收货人',
|
|
|
- 'acceptMobile' => '收货电话',
|
|
|
- 'province' => '省',
|
|
|
- 'city' => '市',
|
|
|
- 'county' => '区',
|
|
|
- 'lgaName' => 'lga name',
|
|
|
+ 'consignee' => 'Consignee',// 收货人
|
|
|
+ 'acceptMobile' => 'Accept Mobile',// 收货电话
|
|
|
+ 'province' => 'Province',// 省
|
|
|
+ 'city' => 'City',// 市
|
|
|
+ 'county' => 'County',// 区
|
|
|
+ 'lgaName' => 'Lga Name',
|
|
|
'cityName' => 'City Name',
|
|
|
- 'detailaddress' => '收货详细地址',
|
|
|
+ 'detailaddress' => 'Address',// 收货详细地址
|
|
|
'email' => 'Email',
|
|
|
];
|
|
|
}
|
|
|
@@ -416,6 +420,20 @@ class OrderForm extends Model
|
|
|
return $this->_model;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * BV分期
|
|
|
+ *
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private function _pvSplit($oPv){
|
|
|
+ $currentPv = $oPv % 30 + 30;
|
|
|
+ $remainPv = $oPv - $currentPv;
|
|
|
+ return [
|
|
|
+ 'current' => $currentPv,
|
|
|
+ 'remain' => $remainPv
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 复销
|
|
|
* @throws Exception
|
|
|
@@ -428,8 +446,10 @@ class OrderForm extends Model
|
|
|
$ids = $this->goodsId;
|
|
|
$totalAmount = 0;
|
|
|
$totalPv = 0;
|
|
|
+ $totalRealPv = 0;
|
|
|
$totalAmountStandard = 0;
|
|
|
$goodsType = ShopGoods::GOODS_TYPE;
|
|
|
+ $this->_remainPv = 0;
|
|
|
$exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0); // 汇率
|
|
|
foreach ($this->goodsNum as $k => $v) {
|
|
|
if ($v) {
|
|
|
@@ -446,9 +466,21 @@ class OrderForm extends Model
|
|
|
$realPv = $goods['PRICE_PV'] * $discount;
|
|
|
$realPriceStandard = $goods['SELL_PRICE_STANDARD'] * $discount;
|
|
|
}
|
|
|
+ if($goods['PV_SPLIT']==1){ // 当商品为PV分期时
|
|
|
+ $pvSplit = $this->_pvSplit($realPv);
|
|
|
+ $currentPv = $pvSplit['current'];
|
|
|
+ $remainPv = $pvSplit['remain'];
|
|
|
+ $totalPv += $currentPv * intval($v);
|
|
|
+ $totalRealPv += $realPv * intval($v);
|
|
|
+ $this->_remainPv += $remainPv * intval($v);
|
|
|
+ }else{
|
|
|
+ $currentPv = $goods['PRICE_PV'];
|
|
|
+ $totalPv += $realPv * intval($v);
|
|
|
+ $totalRealPv += $realPv * intval($v);
|
|
|
+ $remainPv = 0;
|
|
|
+ $this->_remainPv += 0;
|
|
|
+ }
|
|
|
$totalAmount += $realPrice * intval($v);
|
|
|
- $totalPv += $realPv * intval($v);
|
|
|
-
|
|
|
$totalAmountStandard += $realPriceStandard * intval($v);
|
|
|
// if($this->payType=='cash') {
|
|
|
// $discount = $goodsType[$goods['TYPE']]['discount'];
|
|
|
@@ -465,9 +497,10 @@ class OrderForm extends Model
|
|
|
$this->_orderGoods[] = [
|
|
|
'GOODS_ID' => $goods['ID'],
|
|
|
'PRICE' => $goods['SELL_PRICE'],
|
|
|
- 'PV' => $goods['PRICE_PV'],
|
|
|
+ 'PV' => $currentPv, // $goods['PRICE_PV'],
|
|
|
'REAL_PRICE' => $realPrice,
|
|
|
'REAL_PV' => $realPv,
|
|
|
+ 'REMAIN_PV' => $remainPv,
|
|
|
'POINT' => $goods['POINT'],
|
|
|
'BUY_NUMS' => intval($v),
|
|
|
'SKU_CODE' => $goods['GOODS_NO'],
|
|
|
@@ -493,6 +526,7 @@ class OrderForm extends Model
|
|
|
|
|
|
$this->_decAmount = $totalAmount;
|
|
|
$this->_decPv = $totalPv;
|
|
|
+ $this->_realPv = $totalRealPv;
|
|
|
$this->_freight = ($totalAmount >= $freeShipping) ? 0 : $freight;
|
|
|
if($this->_address['PROVINCE']==1){
|
|
|
$this->_freight = 0;
|
|
|
@@ -510,38 +544,33 @@ class OrderForm extends Model
|
|
|
if ($result['code'] !== 200) {
|
|
|
throw new Exception($result['message']);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * 2022-04-28
|
|
|
- * York
|
|
|
- * 支付后减少库存
|
|
|
- */
|
|
|
- foreach ($this->goodsNum as $k => $v){
|
|
|
- if ($v){
|
|
|
- $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
|
|
|
- if ($goods['STORE_NUMS'] >= $this->goodsNum[$k]){
|
|
|
- $data = ShopGoods::find()->where(['ID' => $ids[$k]])->one();
|
|
|
- $goods_store_nums = $data->STORE_NUMS - $this->goodsNum[$k];
|
|
|
- $data->STORE_NUMS = $goods_store_nums;
|
|
|
- $data->update();
|
|
|
- //下单后库存小于等于0 商品下架
|
|
|
- if($goods_store_nums <= 0){
|
|
|
- $data->STATUS = 0;
|
|
|
- $data->UPDATED_AT = Date::nowTime();
|
|
|
- $data->update();
|
|
|
-
|
|
|
- }
|
|
|
- }else{
|
|
|
- throw new Exception($goods['GOODS_NAME'].'库存不足,无法购买商品');
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- // exit();
|
|
|
+ * 2022-04-28
|
|
|
+ * York
|
|
|
+ * 支付后减少库存
|
|
|
+ */
|
|
|
+ foreach ($this->goodsNum as $k => $v){
|
|
|
+ if ($v){
|
|
|
+ $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
|
|
|
+ if ($goods['STORE_NUMS'] >= $this->goodsNum[$k]){
|
|
|
+ $data = ShopGoods::find()->where(['ID' => $ids[$k]])->one();
|
|
|
+ $goods_store_nums = $data->STORE_NUMS - $this->goodsNum[$k];
|
|
|
+ $data->STORE_NUMS = $goods_store_nums;
|
|
|
+ $data->update();
|
|
|
+ //下单后库存小于等于0 商品下架
|
|
|
+ if($goods_store_nums <= 0){
|
|
|
+ $data->STATUS = 0;
|
|
|
+ $data->UPDATED_AT = Date::nowTime();
|
|
|
+ $data->update();
|
|
|
+
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ throw new Exception($goods['GOODS_NAME'].'库存不足,无法购买商品');
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//写入订单
|
|
|
if (!$orderResult = $this->addOrder()) {
|
|
|
@@ -584,7 +613,7 @@ class OrderForm extends Model
|
|
|
if ($payAmount > Balance::getBalanceGarage($loginUserId)) {
|
|
|
return ['code' => 500, 'message' => '车房积分不足,无法购买商品'];
|
|
|
}
|
|
|
- } else{
|
|
|
+// } else{
|
|
|
// if ($payAmount > Balance::getBalanceReconsumePoints($loginUserId)) {
|
|
|
// return ['code' => 500, 'message' => '复消积分不足,无法购买商品'];
|
|
|
// }
|
|
|
@@ -619,6 +648,7 @@ class OrderForm extends Model
|
|
|
$warehouse = '01';
|
|
|
}
|
|
|
$_hasPV = in_array($this->payType, ['exchange', 'tourism_points', 'garage_points']) ? 0 : $this->_decPv;
|
|
|
+ $_hasRealPV = in_array($this->payType, ['exchange', 'tourism_points', 'garage_points']) ? 0 : $this->_realPv;
|
|
|
|
|
|
$ordNo = $this->_generateSn();
|
|
|
$orderModel = new Order();
|
|
|
@@ -630,7 +660,8 @@ class OrderForm extends Model
|
|
|
$orderModel->ORDER_AMOUNT = $this->_decAmount;
|
|
|
$orderModel->PV = $_hasPV;
|
|
|
$orderModel->PAY_AMOUNT = $this->_payAmount;
|
|
|
- $orderModel->PAY_PV = $_hasPV; // 兑换积分不能算业绩
|
|
|
+ $orderModel->PAY_PV = $_hasRealPV; // 兑换积分不能算业绩
|
|
|
+ $orderModel->REMAIN_PV = $this->_remainPv;
|
|
|
$orderModel->PAY_AT = Date::nowTime();
|
|
|
$orderModel->PAY_TYPE = $this->payType;
|
|
|
$orderModel->PERIOD_NUM = $nowPeriodNum;
|
|
|
@@ -695,6 +726,46 @@ class OrderForm extends Model
|
|
|
Balance::changeUserBonus(\Yii::$app->user->id,'reconsume_points', -abs($this->_payAmount),['DEAL_TYPE_ID' => DealType::RECONSUME_POINTS_EXCHANGE,'REMARK' => '会员复销积分兑换']);
|
|
|
}
|
|
|
|
|
|
+// if($this->_remainPv>0) {
|
|
|
+// $oRemainPv = RemainPv::find()->where(['USER_ID' => $userId])->one();
|
|
|
+//
|
|
|
+// $transactionRemain = \Yii::$app->db->beginTransaction();
|
|
|
+// try{
|
|
|
+// $flowRemainPvModel = new FlowRemainPv();
|
|
|
+// $flowRemainPvModel->ID = $this->_generateSn();
|
|
|
+// $flowRemainPvModel->USER_ID = $userId;
|
|
|
+// $flowRemainPvModel->REMAIN_PV_FLOW = $this->_remainPv;
|
|
|
+// $flowRemainPvModel->REMAIN_PV_TOTAL = $oRemainPv['REMAIN_PV'] + $this->_remainPv;
|
|
|
+// $flowRemainPvModel->PERIOD_NUM = $nowPeriodNum;
|
|
|
+// $flowRemainPvModel->UPDATED_AT = Date::nowTime();
|
|
|
+// $flowRemainPvModel->ORDER_SN = 'OS'.$ordNo;
|
|
|
+// if(!$flowRemainPvModel->save()){
|
|
|
+// $this->addErrors($flowRemainPvModel->getErrors());
|
|
|
+// return false;
|
|
|
+// }
|
|
|
+//
|
|
|
+// $oRemainPv = RemainPv::find()->where(['USER_ID' => $userId])->one();
|
|
|
+// if($oRemainPv){
|
|
|
+// $oRemainPv->updateCounters(['REMAIN_PV'=>$this->_remainPv]);
|
|
|
+// }else{
|
|
|
+// $remainPvModel = new RemainPv();
|
|
|
+// $remainPvModel->ID = $this->_generateSn();
|
|
|
+// $remainPvModel->USER_ID = $userId;
|
|
|
+// $remainPvModel->UPDATED_AT = Date::nowTime();
|
|
|
+// $remainPvModel->REMAIN_PV = $this->_remainPv;
|
|
|
+// $remainPvModel->STATUS = 1;
|
|
|
+// if(!$remainPvModel->save()){
|
|
|
+// $this->addErrors($remainPvModel->getErrors());
|
|
|
+// return false;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// $transactionRemain->commit();
|
|
|
+// } catch (Exception $e) {
|
|
|
+// $transactionRemain->rollBack();
|
|
|
+// $this->addError('add', $e->getMessage());
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+// }
|
|
|
return $orderModel;
|
|
|
}
|
|
|
|
|
|
@@ -871,7 +942,7 @@ class OrderForm extends Model
|
|
|
$orderModel->STATUS = 1;
|
|
|
$orderModel->CREATED_AT = Date::nowTime();
|
|
|
$orderModel->CREATE_USER = $loginUserName;
|
|
|
- $orderModel->EMAIL = $email?$email:'tt@qq.com';
|
|
|
+ $orderModel->EMAIL = $email;
|
|
|
if(!$orderModel->save()){
|
|
|
$this->addErrors($orderModel->getErrors());
|
|
|
return false;
|
|
|
@@ -916,4 +987,28 @@ class OrderForm extends Model
|
|
|
}
|
|
|
return $hash;
|
|
|
}
|
|
|
+
|
|
|
+ public function addFakeOrder($userId, $periodNum){
|
|
|
+ $userName = Info::getUserNameByUserId($userId);
|
|
|
+ $ordNo = $this->_generateSn();
|
|
|
+ $orderModel = new Order();
|
|
|
+ $orderModel->SN = 'OS'.$ordNo;
|
|
|
+ $orderModel->DEC_SN = 'DS'.$ordNo;
|
|
|
+ $orderModel->USER_ID = $userId;
|
|
|
+ $orderModel->USER_NAME = $userName;
|
|
|
+ $orderModel->PERIOD_NUM = $periodNum;
|
|
|
+ $orderModel->CREATE_USER = 'FAKE';
|
|
|
+ $orderModel->ORDER_TYPE = 'FO';
|
|
|
+ $orderModel->STATUS = 1;
|
|
|
+ $orderModel->PV = 30;
|
|
|
+ $orderModel->PAY_PV = 30;
|
|
|
+ $orderModel->P_CALC_MONTH = '1970-01-01';
|
|
|
+ $orderModel->CREATED_AT = Date::nowTime();
|
|
|
+ $orderModel->EXPRESS_TYPE = 1;
|
|
|
+ if(!$orderModel->save()){
|
|
|
+ $this->addErrors($orderModel->getErrors());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return $orderModel;
|
|
|
+ }
|
|
|
}
|