zhangguidong 2 роки тому
батько
коміт
2d6f0be246
1 змінених файлів з 77 додано та 67 видалено
  1. 77 67
      application/api/controller/Synthetic.php

+ 77 - 67
application/api/controller/Synthetic.php

@@ -161,82 +161,91 @@ class Synthetic extends Base
      * @param name:id type:int require:1 default:1 desc:藏品ID
      */
     public function synCollection(){
-        $id = input('id');
-        if (!$id) $this->error('参数错误');
-        $info = Db::name('store_collection')
-            ->where('is_deleted',0)
-            ->where('status',1)
-            ->where('type',2)
-            ->where('id',$id)
-            ->find();
-        if (!$info) $this->error('藏品不存在');
-        $now_inventory = getCollectionInventory($id);
-        if ($now_inventory<=0) $this->error('已售罄');
-        if (strtotime($info['sell_time'])>time()) $this->error('未开始,无法合成');
-        if (strtotime($info['end_time'])<time())  $this->error('已结束,无法合成');
+        if (redisSetNx('Synollection'.$this->uid,3)) {
+            $id = input('id');
+            if (!$id) $this->error('参数错误');
+            $info = Db::name('store_collection')
+                ->where('is_deleted', 0)
+                ->where('status', 1)
+                ->where('type', 2)
+                ->where('id', $id)
+                ->find();
+            if (!$info) $this->error('藏品不存在');
+            $now_inventory = getCollectionInventory($id);
+            if ($now_inventory <= 0) $this->error('已售罄');
+            if (strtotime($info['sell_time']) > time()) $this->error('未开始,无法合成');
+            if (strtotime($info['end_time']) < time()) $this->error('已结束,无法合成');
 
 //        $info_count = Db::name('store_order_info')->where('mid',$this->uid)->where('c_id',$id)->count();
 //        if ($info_count) $this->error('已合成过,只能合成一次');
 
-        //获取是否已经铸造hash
-        $is_nft = Db::name('hash2')->where('goods_id',$id)->where('success',1)->find();
-        if (!$is_nft) $this->error('nft未上架,无法合成');
-        $is_exchange = $this->check_exchange($id,$this->uid);
-        if (!$is_exchange) $this->error('材料不足,无法合成');
-        $com = true;
-        Db::startTrans();
-        try {
-            $material = Db::name('store_collection_material')
-                ->where('cid',$id)
-                ->select();
-            foreach ($material as &$v){
-                Db::name('store_order_info')
-                    ->where('c_id',$v['c_id'])
-                    ->where('mid',$this->uid)
-                    ->where('status','neq',2)
-                    ->where('is_destruction',1)
-                    ->limit($v['num'])
-                    ->order('id asc')
-                    ->update(['is_destruction'=>0]);
+            //获取是否已经铸造hash
+            $is_nft = Db::name('hash2')->where('goods_id', $id)->where('success', 1)->find();
+            if (!$is_nft) $this->error('nft未上架,无法合成');
+            $is_exchange = $this->check_exchange($id, $this->uid);
+            if (!$is_exchange) $this->error('材料不足,无法合成');
+            $com = true;
+            Db::startTrans();
+            try {
+                $material = Db::name('store_collection_material')
+                    ->where('cid', $id)
+                    ->select();
+                foreach ($material as &$v) {
+                    Db::name('store_order_info')
+                        ->where('c_id', $v['c_id'])
+                        ->where('mid', $this->uid)
+                        ->where('status', 'neq', 2)
+                        ->where('is_destruction', 1)
+                        ->limit($v['num'])
+                        ->order('id asc')
+                        ->update(['is_destruction' => 0]);
+                }
+
+                //获取排名
+                $rank = getRanking($id) + 1;
+                $tag = getTag($id, $rank, $info['inventory']);
+                saveRanking($id);
+                $collectors_hash = '';
+                $date = [
+                    'order_id' => 0,
+                    'order_no' => get_order_sn(),
+                    'tag' => $tag,
+                    'mid' => $this->uid,
+                    'c_id' => $id,
+                    'name' => $info['name'],
+                    'cover' => $info['cover'],
+                    'pro_info' => json_encode($info, true),
+                    'type' => $info['type'],
+                    'tokenid' => $is_nft['class_id'],
+                    'nfttype' => $is_nft['operationId'],
+                    'collectors_hash' => $collectors_hash,
+                    'collectors_hash_time' => '',
+                    'status' => 5
+                ];
+                Db::name('store_order_info')->insert($date);
+
+                Db::commit();
+            } catch (\Exception $e) {
+                $com = false;
+                Db::rollback();
             }
+            if ($com) {
+                setMemberInfoHash($this->uid);
+                //减掉库存
+                loseCollectionInventory($id, 1);
+                DelRedisSetNx('Synollection'.$this->uid);
 
-            //获取排名
-            $rank = getRanking($id)+1;
-            $tag = getTag($id,$rank,$info['inventory']);
-            saveRanking($id);
-            $collectors_hash = '';
-            $date = [
-                'order_id'=>0,
-                'order_no'=>get_order_sn(),
-                'tag'=>$tag,
-                'mid'=>$this->uid,
-                'c_id'=>$id,
-                'name'=>$info['name'],
-                'cover'=>$info['cover'],
-                'pro_info'=>json_encode($info,true),
-                'type'=>$info['type'],
-                'tokenid'=>$is_nft['class_id'],
-                'nfttype'=>$is_nft['operationId'],
-                'collectors_hash'=>$collectors_hash,
-                'collectors_hash_time'=>'',
-                'status'=>5
-            ];
-            Db::name('store_order_info')->insert($date);
-
-            Db::commit();
-        }catch (\Exception $e){
-            $com=false;
-            Db::rollback();
-        }
-        if ($com){
-            setMemberInfoHash($this->uid);
-            //减掉库存
-            loseCollectionInventory($id,1);
+                $this->success('合成成功');
+            }
+            DelRedisSetNx('Synollection'.$this->uid);
+
+            $this->error('合成失败,请稍后重试');
 
-            $this->success('合成成功');
         }
-        $this->error('合成失败,请稍后重试');
+        else{
+            $this->error('请求过快');
 
+        }
 
 
     }
@@ -245,4 +254,5 @@ class Synthetic extends Base
 
 
 
+
 }