Browse Source

储值卡

lizhen_gitee 1 year ago
parent
commit
c0297962de

+ 3 - 3
application/api/controller/company/Coupon.php

@@ -45,7 +45,7 @@ class Coupon extends Apic
     public function changestatus(){
         $id = input('id',0);
         $info = Db::name('coupons')->where('id',$id)->update(['status'=>0]);
-        $this->success(1,$info);
+        $this->success();
     }
 
     //详情
@@ -85,7 +85,7 @@ class Coupon extends Apic
         $this->success('删除成功');
     }
 
-    //统一核销
+    //统一核销,获取信息
     public function gethexiao(){
         $code = input('code','');
         $code = explode('_',$code);
@@ -122,7 +122,7 @@ class Coupon extends Apic
         $this->success(1,$check);
     }
 
-    //统一核销
+    //统一核销,提交
     public function hexiao(){
         $code = input('code','');
         $code = explode('_',$code);

+ 118 - 0
application/api/controller/company/Recharge.php

@@ -0,0 +1,118 @@
+<?php
+
+namespace app\api\controller\company;
+
+use app\common\controller\Apic;
+use think\Db;
+
+/**
+ * 储值卡
+ */
+class Recharge extends Apic
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = '*';
+
+
+    //首页
+    public function lists(){
+        $status = input('status',1);
+
+        $where = [
+            'company_id' => $this->auth->company_id,
+            'status'     => $status,
+        ];
+
+        $list = Db::name('recharge_config')->where($where)->order('id asc')->select();
+
+        //追加赠送
+        if(!empty($list)){
+            $config_ids = array_column($list,'id');
+            $gift = Db::name('recharge_gift')->alias('gift')
+                ->field('gift.*,coupons.name,coupons.info,coupons.days')
+                ->join('coupons','gift.coupon_id = coupons.id','LEFT')
+                ->where('gift.config_id','IN',$config_ids)
+                ->where('coupons.status',1)
+                ->select();
+
+            foreach($list as $key => &$val){
+                $val['gift'] = [];
+                foreach($gift as $k => $v){
+                    if($val['id'] == $v['config_id']){
+                        $val['gift'][] = $v;
+                    }
+                }
+            }
+
+        }
+        $this->success(1,$list);
+    }
+
+    //新增
+    public function add(){
+        $field = ['price','giftprice'];
+        $data = request_post_hub($field);
+
+        $data['company_id'] = $this->auth->company_id;
+        $data['status'] = 1;
+
+        Db::startTrans();
+        $config_id = Db::name('recharge_config')->insertGetId($data);
+        if(!$config_id){
+            Db::rollback();
+            $this->error('添加失败');
+        }
+
+        //赠送卡券
+        $gift_data = input('gift_data','','trim');
+        $gift_data = json_decode(htmlspecialchars_decode($gift_data),true);
+
+        if(is_array($gift_data) && !empty($gift_data)){
+            $recharge_gift = [];
+            foreach($gift_data as $key => $val){
+                $recharge_gift[] = [
+                    'config_id' => $config_id,
+                    'coupon_id' => $val['coupon_id'],
+                    'number'    => $val['number'],
+                ];
+            }
+            if(!empty($recharge_gift)){
+                $rs_gift = Db::name('recharge_gift')->insertAll($recharge_gift);
+                if($rs_gift === false){
+                    Db::rollback();
+                    $this->error('添加失败');
+                }
+            }
+        }
+
+        Db::commit();
+
+        $this->success('添加成功');
+    }
+
+    //上下架
+    public function changestatus(){
+        $id = input('id',0);
+        $info = Db::name('recharge_config')->where('id',$id)->update(['status'=>0]);
+        $this->success();
+    }
+
+    //删除
+    public function delete(){
+        $id = input('id','');
+
+        $check = Db::name('recharge_config')->where('id',$id)->where('company_id',$this->auth->company_id)->find();
+        if(empty($check)){
+            $this->error('不存在的储值卡');
+        }
+
+        Db::name('recharge_config')->where('id',$id)->delete();
+        Db::name('recharge_gift')->where('config_id',$id)->delete();
+        $this->success('删除成功');
+    }
+
+
+
+
+
+}