作者 jinglong
1 个管道 的构建 通过 耗费 3 秒

修改支付成功回调减少库存

@@ -579,10 +579,23 @@ class Common @@ -579,10 +579,23 @@ class Common
579 //销量增加1 579 //销量增加1
580 $res = self::findSoftWhereData('order',['pay_order_sn'=>$out_trade_no,'status'=>$status[2]],'id,uid'); 580 $res = self::findSoftWhereData('order',['pay_order_sn'=>$out_trade_no,'status'=>$status[2]],'id,uid');
581 if($res){ 581 if($res){
582 - $res1 = self::selectSoftWhereData('ogoods',['o_id'=>$res['id']],'id,g_id'); 582 + $res1 = self::selectSoftWhereData('ogoods',['o_id'=>$res['id']],'id,g_id,style');
583 $g_ids = array_column($res1,'g_id'); 583 $g_ids = array_column($res1,'g_id');
584 //减库存 584 //减库存
585 - self::decStock(['id'=>['in',$g_ids]]); 585 + $goodsModel = new \app\admin\model\Goods();
  586 + //查询商品的库存
  587 + $res_stock = self::selectSoftWhereData('goods',['id'=>['in',$g_ids]],'id,style g_style,stock');
  588 + foreach($res1 as $value){
  589 + foreach($res_stock as $g_value){
  590 + if($value['g_id'] == $g_value['id']){
  591 + $arr_stock = explode('|',$g_value['stock']);
  592 + $s_index = array_search($value['style'],self::salePrice($g_value['g_style']));
  593 + $stock = self::salePrice($g_value['stock'])[$s_index] - 1;
  594 + $arr_stock[$s_index] = $stock;
  595 + $goodsModel->where(['id'=>$value['g_id']])->update('stock',implode('|',$arr_stock));
  596 + }
  597 + }
  598 + }
586 //增加销售 599 //增加销售
587 self::incSales(['id'=>['in',$g_ids]]); 600 self::incSales(['id'=>['in',$g_ids]]);
588 //删除购物车 601 //删除购物车