wupengfei 2 年之前
父节点
当前提交
0e8b8b9200
共有 3 个文件被更改,包括 56 次插入69 次删除
  1. 15 0
      application/common/service/PowerRedis.php
  2. 27 58
      application/store/controller/Power.php
  3. 14 11
      application/store/view/power/send.html

+ 15 - 0
application/common/service/PowerRedis.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace app\common\service;
+use think\cache\driver\Redis;
+
+class PowerRedis
+{
+    protected $pre = 'POWER';
+    public static function a()
+    {
+        $redis =  new Redis();
+    }
+
+
+}

+ 27 - 58
application/store/controller/Power.php

@@ -132,69 +132,38 @@ class Power extends Controller
      */
     public function send()
     {
-        if($this->request->post()){
-            $data = $this->request->post();
-            if (!isset($data['mid']) || $data['mid']==''){
-                $this->error('请选择用户');
-            }
-            $inventory = Db::name($this->table)->where('id',$data['id'])->value('inventory');
-            $info = Db::name($this->table)->where('id',$data['id'])->find();
-
-            $redis = new Redis();
-            $zhuzao_count = $redis->Llen('collectionHash_'.$data['id']);
-            $com = true;
-            Db::startTrans();
-            try {
-                $array = [];
-                for ($i=0;$i<$data['number'];$i++){
-                    //获取排名
-                    $rank = getRanking($data['id'])+1;
-                    $tag = getTag($data['id'],$rank,$inventory);
-                    saveRanking($data['id']);
-                    $company = '梵易(广州)艺术有限公司';
-                    $hash = getCompanyHash($data['id']);
-                    $company_hash = $hash['hash'];
-                    $company_hash_time = $hash['create_at'];
-                    $tokenid = $hash['tokenid'];
-                    Db::name('hash')->where('hash',$hash['hash'])->update(['status'=>1]);
-                    $collectors_hash = '';
-                    $date = [
-                        'order_no'=>get_order_sn(),
-                        'tag'=>$tag,
-                        'mid'=>$data['mid'],
-                        'c_id'=>$data['id'],
-                        'name'=>$info['name'],
-                        'cover'=>$info['cover'],
-                        'pro_info'=>json_encode($info,true),
-                        'company'=>$company,
-                        'company_hash'=>$company_hash,
-                        'company_hash_time'=>$company_hash_time,
-                        'ddcid'=>$tokenid,
-                        'collectors_hash'=>$collectors_hash,
-                        'collectors_hash_time'=>''
-                    ];
-                    $array[] = $date;
-                }
-                Db::name('store_order_info')->insertAll($array);
-
-                Db::commit();
-            } catch (\Exception $e){
-                Db::rollback();
-                $com = false;
-            }
-            if ($com){
-                //减掉库存
-                loseCollectionInventory($data['id'],$data['number']);
-                $this->success('赠送成功');
-            }else{
-                $this->error('赠送失败');
-            }
-        }else{
+        if($this->request->isGet()) {
             $id=$this->request->get('id');
             $this->assign('id',$id);
             $goods_list =  Db::name('store_collection')->where(['is_deleted'=>0,'type'=>1])->order('id desc')->column('name','id');
             $this->fetch('',['goods_list'=>$goods_list]);
         }
+
+        if($this->request->post()){
+            $data = $this->request->post();
+            $goods_id = $this->request->post('send_goods');
+            $coll_id = $this->request->post('coll_id');
+            if(!$goods_id)  $this->error('请选择藏品');
+            $coll_info = getCollectionInfoHash($goods_id);// 赠送的藏品信息
+            if ($coll_info['is_deleted']==1 || $coll_info['status']==0) $this->error('藏品已下架');
+            $inventory = getCollectionInventory($goods_id);
+            $where=  [];
+            $where[] = ['c_id','=',$coll_id];
+            $where[] = ['resale_status','=',1];
+            $where[] = ['is_destruction','=',1];
+            $num = Db::name('store_order_info')->where($where)->count();// 需要赠送总数
+            if ($inventory < 1 || $inventory<$num) $this->error('库存不足');
+
+            //获取是否已经铸造hash
+            $hashCount = getLenCollection($goods_id);
+            if ((!$hashCount || $hashCount<$num) && $coll_info['type'] != 3) $this->error('hash未铸造,无法购买');
+            //先减掉库存
+            loseCollectionInventory($goods_id,$num);
+
+            Db::name('collection_power_send')->insert(['coll_id'=>$coll_id,'send_goods'=>$goods_id,'power_id'=>$data['id']]);
+
+            $this->success('设置成功,稍后赠送用户藏品');
+        }
     }
 
 

+ 14 - 11
application/store/view/power/send.html

@@ -1,24 +1,27 @@
-<form onsubmit="return false;"  action="{:url('send')}" data-auto="true" method="post" class='layui-form layui-card' autocomplete="off">
-    <div class="layui-card-body think-box-shadow padding-left-40">
+<form onsubmit="return false;" action="{:request()->url()}" data-auto="true" method="post" class='layui-form layui-card' autocomplete="off">
+    <div class="layui-card-body">
+
+        <input type="hidden" name="coll_id" value="{$vo.coll_id|default=''}"/>
         <div class="layui-row margin-bottom-15">
-            <label class="layui-col-xs2 think-form-label">商品</label>
+            <label class="layui-col-xs2 think-form-label">赠送藏品</label>
             <label class="layui-col-xs10">
                 <select class="layui-select" name="send_goods">
                     <option value="0">请选择</option>
                     {foreach $goods_list as $k=>$v}
-                        <option  value="{$k}">{$v} -- {$k}</option>
+                        <option value="{$k}">{$v} -- {$k}</option>
                     {/foreach}
                 </select>
             </label>
         </div>
 
-        <div class="layui-form-item text-center" style="margin-top:  200px">
-            {notempty name='id'}<input type="hidden" name="id" value="{$id}">{/notempty}
-            <button class="layui-btn layui-btn-danger" onclick="history.go(-1);" type="button">取消编辑</button>
-            <button class="layui-btn" type="submit">保存</button>
-        </div>
+    </div>
+    <div class="hr-line-dashed" style="margin-top:  200px"></div>
+    <div class="layui-form-item text-center">
+        {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}
+        <button class="layui-btn" type='submit'>保存数据</button>
+        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消吗?" data-close>取消编辑</button>
     </div>
 </form>
 <script>
-    layui.form.render();
-</script>
+    window.form.render();
+</script>