瀏覽代碼

合成订单

afa 7 月之前
父節點
當前提交
0adc9c5311
共有 2 個文件被更改,包括 13 次插入10 次删除
  1. 5 3
      application/api/controller/Synthesis.php
  2. 8 7
      application/common/model/UserSynthesis.php

+ 5 - 3
application/api/controller/Synthesis.php

@@ -9,7 +9,7 @@ use app\common\model\ProductOrder;
 use think\Db;
 use Exception;
 use app\api\logic\WelfareLoginc;
-use app\common\model\UserModel;
+use app\common\model\UserSynthesis;
 use app\common\model\Synthesis as SynthesisModel;
 
 
@@ -67,7 +67,7 @@ class Synthesis extends Api
     /*
      * 合成
      */
-    public function create(ProductOrder $productOrder, UserModel $userModel)
+    public function create(ProductOrder $productOrder, UserSynthesis $userSynthesis)
     {
         $id         = $this->request->post('id', 0, 'intval');
         $num        = $this->request->post('num', 0, 'intval');
@@ -76,7 +76,6 @@ class Synthesis extends Api
         //合成详情
         $synthesis = SynthesisModel::get($id);
         if (empty($synthesis)) $this->error(__("合成活动不存在"));
-   
         $time = time();
         if ($synthesis->start_time > $time || $synthesis->end_time < $time)$this->error(__("合成活动已结束"));
         if ($synthesis->num + $num > $synthesis->stock)$this->error(__("库存不足"));
@@ -89,6 +88,9 @@ class Synthesis extends Api
 
             // 添加新订单
             WelfareLoginc::setUserProductOrder($num, 0, $synthesis->id, 0, $synthesis->product_id, $this->auth->id, $productOrder::Synthesi);
+ 
+            //合成记录
+            $userSynthesis::setUserSynthesisLog($this->auth->id, $id, $num, $productList);
 
             $synthesis->num += $num;
             $synthesis->save();

+ 8 - 7
application/common/model/UserSynthesis.php

@@ -31,14 +31,15 @@ class UserSynthesis extends Model
 
    
       //设置用户合成记录
-      public static function setUserSynthesisLog(int $uid, int $transferId)
+      public static function setUserSynthesisLog(int $uid, int $synthesisId, int $num, string $note)
       {
-           $rows = self::where('user_id', $uid)->where('transfer_id', $transferId)->find();
-           if($rows){
-               return $rows->delete();
-           }else{
-               return self::create(['user_id'=>$uid, 'transfer_id'=>$transferId]);
-           }
+           return self::create([
+               'user_id'      => $uid,
+               'synthesis_id' => $synthesisId,
+               'num'          => $num,
+               'note'         => $note
+           ]);
+       
       }