Browse Source

直推收益

afa 10 months ago
parent
commit
5d8a71dd40

+ 0 - 1
application/api/controller/Home.php

@@ -178,7 +178,6 @@ class Home extends Api
             ->where('status', $productarea::NORMAL)
             ->where($map)
             ->paginate($this->pageSize);
-      
         // 提交事务
         $this->success('', $list);
     }

+ 4 - 4
application/api/controller/Order.php

@@ -33,7 +33,8 @@ class Order extends Api
         if(!$validate->scene('add')->check($params)) $this->error($validate->getError());
         
         $order_info = $productPopular->where('id', $params['order_id'])->find();
-        if(empty($order_info)) $this->error( __("参数有误,无可用产品"));
+        if($order_info->num == $order_info->stock) $this->error(__("库存不足"));
+        if(empty($order_info)) $this->error(__("参数有误,无可用产品"));
         $order_data['order_id']  = $params['order_id'];
         $order_data['product_id']= $params['product_id'];
         $order_data['price']     = $order_info['price'];
@@ -54,20 +55,19 @@ class Order extends Api
             $productOrder->create($order_data);
 
             //修改区域状态
-            $productArea->where('id', $order_data['area_id'])->update(['status'=> ProductLists::STOP]);
+            $productArea->where('id', $order_data['area_id'])->setField('status', ProductLists::STOP);
 
             //余额记录
             $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$order_info['price'], $ledgerWalletModel::Popular, $this->auth->id);
 
             //直推收益: pv* ×10%
-            if($order_info['pv'] > 0 && $this->auth->parent_id > 0){
+            if($order_info['pv'] > 0 && $this->auth->parent_id > 0 && $productOrder::getEffectiveOrder($this->auth->parent_id) > 0){
                 $pv = bcmul($order_info['pv'], getConfig('pv_rate'), 2);
                 $ledgerWalletModel->changeWalletAccount($this->auth->parent_id, Asset::TOKEN, $pv, $ledgerWalletModel::Direct, $this->auth->id);
             }
             //扣除库存
             if($order_info->stock == 1 || time() >= $order_info->end_time) $order_info->status= $productPopular::STOP;
             $order_info->num  += 1;
-            $order_info->stock-= 1;
             $order_info->save();
             // 提交事务
             Db::commit();

+ 1 - 0
application/api/lang/en/order.php

@@ -17,6 +17,7 @@ return [
       '赠送用户不存在'                         => 'The gift user does not exist',
       '赠送用户不能是自己'                     => 'The user who sends the gift cannot be yourself',
       '暂无物流信息'                           => 'No logistics information',
+      '库存不足'                               => 'Insufficient inventory',
 
 
 

+ 3 - 2
application/api/lang/zh-cn/order.php

@@ -15,7 +15,8 @@ return [
       '赠送'                  => '赠送',
       '关闭'                  => '关闭',
       '赠送用户不存在'         => '赠送用户不存在',
-      '赠送用户不能是自己'      => '赠送用户不能是自己',
-      '暂无物流信息'             => '暂无物流信息',
+      '赠送用户不能是自己'     => '赠送用户不能是自己',
+      '暂无物流信息'           => '暂无物流信息',
+      '库存不足'              => '库存不足',
       
 ];

+ 8 - 0
application/common/model/ProductOrder.php

@@ -49,6 +49,14 @@ class ProductOrder extends Model
         self::Closure           => '关闭',
     ];
 
+
+    //获取有效订单
+    public static function getEffectiveOrder(int $uid)
+    {
+        return self::where('user_id', $uid)->where('status', '<', self::Shipped)->count();
+    }
+
+
     public static function getStatusList()
     {
         return [self::Ordered => __('已下单'), self::Paid  => __('已付款'), self::Transferred => __('已转让'),