xxxrrrdddd 2 rokov pred
rodič
commit
8f1444be43

+ 5 - 8
application/admin/controller/Goods.php

@@ -324,21 +324,18 @@ class Goods extends Backend
                     ->column('uid');
                 if(count($uids)) {
                     #todo:HASH
-                    /*$hash = GoodsHash::zero()->queryGoods($row['id'])->limit(count($uids))->lock(true)->select();
-                     if(count($hash)!=count($uids)){
-                         $this->error('hash数量不足');
-                     }*/
+                    $hash = GoodsHash::zero()->queryGoods($row['id'])->limit(count($uids))->lock(true)->select();
                     foreach ($uids as $key=>$uid) {
-                        //$currentHash=$hash[$key];
+                        $currentHash=$hash[$key]??null;
                         \datamodel\UsersGoods::create([
                             'uid'=>$uid,
                             'goods_id'=>$row['id'],
                             'price'=>$row['price'],
                             'is_buy_before'=>2,
-                            //'token_id'=>$currentHash['token_id'],
+                            'token_id'=>$currentHash['token_id']??null,
                         ]);
-                        //ChainLogic::instance()->buy($currentHash,\datamodel\Users::get($uid));
-                        //$currentHash->setOrder(-3);
+                        ChainLogic::instance()->buy($currentHash,\datamodel\Users::get($uid));
+                        $currentHash && $currentHash->setOrder(-3);
                     }
                 }
             }

+ 3 - 7
application/admin/controller/Users.php

@@ -314,19 +314,15 @@ class Users extends Backend
            if(!$result) return json(['code'=>0,'msg'=>'赠送失败']);
            Db::startTrans();
            #todo:HASH
-           /*$hash=GoodsHash::zero()->queryGoods($data['goods_id'])->lock(true)->find();
-           if(!$hash){
-               Db::rollback();
-               return json(['code'=>0,'msg'=>'暂无可用hash']);
-           }*/
+           $hash=GoodsHash::zero()->queryGoods($data['goods_id'])->lock(true)->find();
            $goods['uid'] = $ids;
            $goods['price'] = $price;
            $goods['goods_id'] = $data['goods_id'];
            $goods['create_time'] = $time;
-           //$goods['token_id']=$hash['token_id'];
+           $goods['token_id']=$hash['token_id']??null;
            $result =  (new \app\admin\model\UsersGoods())->insertGetId($goods);
             if($result) {
-                //$hash->setOrder(-1);
+                $hash && $hash->setOrder(-1);
                 Db::commit();
                 return json(['code'=>1,'msg'=>'赠送成功']);
             }

+ 7 - 4
extend/logicmodel/ChainLogic.php

@@ -78,9 +78,9 @@ class ChainLogic
 
     public function transfer(Users $fromUser,?GoodsHash $goodsHash,Users $toUser){
         #todo:屏蔽
-        return null;
+        //return null;
         if(!$goodsHash){
-            return ;
+            return null;
         }
         $hash=$this->request('transfer',[
             'from'=>$fromUser['wallet_address'],
@@ -90,9 +90,12 @@ class ChainLogic
         return $hash['txHash'];
     }
 
-    public function buy(GoodsHash $goodsHash,Users $toUser){
+    public function buy(?GoodsHash $goodsHash,Users $toUser){
+        if(!$goodsHash){
+            return null;
+        }
         #todo:屏蔽
-        return null;
+        //return null;
         $hash=$this->request('transfer',[
             'from'=>$this->getMainAccount(),
             'to'  =>$toUser['wallet_address'],

+ 8 - 16
extend/logicmodel/GoodsLogic.php

@@ -468,11 +468,7 @@ class GoodsLogic
         $time = date('Y-m-d H:i:s');
         Db::startTrans();
         #todo:HASH
-       /* $hash=GoodsHash::zero()->queryGoods($goods_id)->lock(true)->find();
-        if(!$hash){
-            Db::rollback();
-            return Response::fail('无可用hash');
-        }*/
+        $hash=GoodsHash::zero()->queryGoods($goods_id)->lock(true)->find();
         $needSubMoney=$buyType===0||$buyType===1;
         if($pay_type == 1){
             //余额抵扣
@@ -496,19 +492,19 @@ class GoodsLogic
             $order['create_time'] = $time;
             $order['status'] = 1;
             $order['buy_type'] = $buyType;
-            //$order['trans_hash']=ChainLogic::instance()->buy($hash,Users::get($uid));
+            $order['trans_hash']=ChainLogic::instance()->buy($hash,Users::get($uid));
             $result = $ordersGoodsData->insertGetId($order);
             if(!$result){
                 Db::rollback();
                 return Response::fail('购买失败');
             }
-            //$hash->setOrder($result);
+            $hash && $hash->setOrder($result);
             $goods['uid'] = $uid;
             $goods['goods_id'] = $goods_id;
             $goods['price'] = $price;
             $goods['create_time'] = date('Y-m-d H:i:s');
             $goods['is_buy_before']=$buyType;
-            //$goods['token_id']=$hash['token_id'];
+            $goods['token_id']=$hash['token_id']??null;
             $result =  $this->usersGoodsData->saveEntityAndGetId($goods);
             if($result >0){
                 Db::commit();
@@ -647,11 +643,7 @@ class GoodsLogic
             return Response::fail('积分不足');
         }
         #todo:HASH
-       /*$hash=GoodsHash::zero()->queryGoods($goods_id)->lock(true)->find();
-        if(!$hash){
-            Db::rollback();
-            return Response::fail('无可用hash');
-        }*/
+       $hash=GoodsHash::zero()->queryGoods($goods_id)->lock(true)->find();
         //生成购买订单
         $order['uid'] = $uid;
         $order['goods_id'] = $goods_id;
@@ -664,18 +656,18 @@ class GoodsLogic
         $order['pay_time'] = $time;
         $order['create_time'] = $time;
         $order['status'] = 1;
-        //$order['trans_hash'] = ChainLogic::instance()->buy($hash,Users::get($uid));
+        $order['trans_hash'] = ChainLogic::instance()->buy($hash,Users::get($uid));
         $result = (new OrdersGoods())->insertGetId($order);
         if(!$result){
             Db::rollback();
             return Response::fail('兑换失败');
         }
-        //$hash->setOrder($result);
+        $hash && $hash->setOrder($result);
         $goods['uid'] = $uid;
         $goods['goods_id'] = $goods_id;
         $goods['price'] = $price;
         $goods['create_time'] = date('Y-m-d H:i:s');
-        //$goods['token_id']=$hash['token_id'];
+        $goods['token_id']=$hash['token_id']??null;
         $result =  $this->usersGoodsData->saveEntityAndGetId($goods);
         if($result >0){
             Db::commit();

+ 4 - 7
extend/logicmodel/award/Recommend.php

@@ -77,19 +77,16 @@ class Recommend extends Award
                     if($goods){
                         $recommendData->where(['id'=>$recommend['id']])->setDec('stock',1);
                         #todo:HASH
-                        /*$hash=GoodsHash::zero()->queryGoods($goods['id'])->lock(true)->find();
-                        if(!$hash){
-                            api_error('暂无可用hash,无法赠送');
-                        }*/
+                        $hash=GoodsHash::zero()->queryGoods($goods['id'])->lock(true)->find();
                         $usersGoods = [
                             'uid'=>$uid,
                             'goods_id'=>$goods['id'],
                             'price'=>$goods['price'],
                             'create_time'=>date('Y-m-d H:i:s'),
-                            //'token_id'=>$hash['token_id'],
+                            'token_id'=>$hash['token_id']??null,
                         ];
-                        //$hash->setOrder(-2);
-                        //ChainLogic::instance()->buy($hash,Users::get($uid));
+                        $hash && $hash->setOrder(-2);
+                        ChainLogic::instance()->buy($hash,Users::get($uid));
                         $result = (new UsersGoods())->insertGetId($usersGoods);
                         if($result){
                             $this->record($uid,2,0,$from_uid,$this->award_id,$awardInfo['name'],'推荐奖励',$awardInfo['field'],$recommend['goods_id'],0,2);