|
|
@@ -73,8 +73,8 @@ class OrderForm extends Model
|
|
|
public function rules()
|
|
|
{
|
|
|
return [
|
|
|
- [['sn', 'expressCompany', 'orderTrackNo', 'status', 'remark','type','addressId','payType','goodsId','goodsNum', 'payPassword','userName','consignee','acceptMobile','province','city','county','detailaddress','email'], 'trim'],
|
|
|
- [['sn', 'expressCompany', 'orderTrackNo', 'status', 'remark','type','addressId','payType','goodsId','goodsNum', 'payPassword','userName','consignee','acceptMobile','province','city','county','detailaddress','email'], 'required'],
|
|
|
+ [['sn', 'expressCompany', 'orderTrackNo', 'status', 'remark','type','addressId','payType','goodsId','goodsNum', 'payPassword','userName','consignee','acceptMobile','province','city','county','detailaddress'/*,'email'*/], 'trim'],
|
|
|
+ [['sn', 'expressCompany', 'orderTrackNo', 'status', 'remark','type','addressId','payType','goodsId','goodsNum', 'payPassword','userName','consignee','acceptMobile','province','city','county','detailaddress'/*,'email'*/], 'required'],
|
|
|
[['status'], 'isStatus'],
|
|
|
[['addressId'], 'isAddress'],
|
|
|
[['payType'], 'isPayType'],
|
|
|
@@ -487,7 +487,39 @@ class OrderForm extends Model
|
|
|
$result = $this->getBalanceAdequate($this->payType, $this->_payAmount);
|
|
|
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();
|
|
|
|
|
|
//写入订单
|
|
|
if (!$orderResult = $this->addOrder()) {
|
|
|
@@ -706,7 +738,41 @@ class OrderForm extends Model
|
|
|
if ($this->_payAmount > Balance::getBalanceReconsumePoints($loginUserId)) {
|
|
|
throw new Exception('复消积分不足,无法购买商品');
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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();
|
|
|
+
|
|
|
+
|
|
|
//写入订单
|
|
|
if (!$orderResult = $this->addUserOrder()) {
|
|
|
throw new Exception(Form::formatErrorsForApi($orderResult->getErrors()));
|