瀏覽代碼

优惠券,首页,提现

lizhen_gitee 1 年之前
父節點
當前提交
916ad21729

+ 108 - 0
application/api/controller/company/Coupon.php

@@ -0,0 +1,108 @@
+<?php
+
+namespace app\api\controller\company;
+
+use app\common\controller\Apic;
+use think\Db;
+
+/**
+ * 优惠券
+ */
+class Coupon extends Apic
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = '*';
+
+    public function _initialize()
+    {
+        parent::_initialize();
+    }
+
+
+    //优惠券管理
+    public function lists(){
+        $status = input('status',1);
+
+        $where = [
+            'company_id' => $this->auth->id,
+            'type' => 1,
+        ];
+
+        if($status == 1){ //未开始
+            $where['usetimestart'] = ['gt',time()];
+        }elseif($status == 2){ //进行中
+            $where['usetimestart'] = ['lt',time()];
+            $where['usetimeend'] = ['gt',time()];
+        }else{  //已结束
+            $where['usetimeend'] = ['lt',time()];
+        }
+
+        $list = Db::name('coupons')->where($where)->order('id desc')->autopage()->select();
+        $this->success(1,$list);
+    }
+
+    //新增
+    public function add(){
+        $field = ['enough','amount','number','limit','usetimestart','usetimeend'];
+        $data = request_post_hub($field);
+
+        $data['company_id'] = $this->auth->id;
+        $data['type'] = 1;
+        $data['score'] = 0;
+        $data['stock'] = $data['number'];
+        $data['createtime'] = time();
+        $data['updatetime'] = time();
+
+        Db::name('coupons')->insertGetId($data);
+        $this->success('添加成功');
+    }
+
+    public function info(){
+        $id = input('id',0);
+        $info = Db::name('coupons')->where('id',$id)->find();
+        $this->success(1,$info);
+    }
+
+    //编辑
+    public function edit(){
+        $id = input('id','');
+        $check = Db::name('coupons')->where('id',$id)->where('company_id',$this->auth->id)->find();
+
+        if(empty($check)){
+            $this->error('不存在的优惠券');
+        }
+        if($check['usetimestart'] < time()){
+            $this->error('优惠券已经进行中,不能修改');
+        }
+
+        //
+        $field = ['enough','amount','number','limit','usetimestart','usetimeend'];
+        $data = request_post_hub($field);
+        $data['stock'] = $data['number'];
+        $data['updatetime'] = time();
+
+        Db::name('coupons')->where('id',$id)->update($data);
+        $this->success('编辑成功');
+    }
+
+    //删除
+    public function delete(){
+        $id = input('id','');
+        $check = Db::name('coupons')->where('id',$id)->where('company_id',$this->auth->id)->find();
+
+        if(empty($check)){
+            $this->error('不存在的优惠券');
+        }
+
+        if($check['usetimestart'] < time()){
+            $this->error('优惠券已经进行中,不能删除');
+        }
+
+        Db::name('coupons')->where('id',$id)->delete();
+        $this->success('删除成功');
+    }
+
+
+
+
+}

+ 70 - 0
application/api/controller/company/Index.php

@@ -0,0 +1,70 @@
+<?php
+
+namespace app\api\controller\company;
+
+use app\common\controller\Apic;
+use think\Db;
+
+/**
+ * 会员接口
+ */
+class Index extends Apic
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = '*';
+
+    public function _initialize()
+    {
+        parent::_initialize();
+    }
+
+    //首页
+    public function index(){
+
+
+    }
+
+    //首页轮播
+    public function banner(){
+        $where = [
+            'company_id' => $this->auth->company_id,
+            'status'     => 1,
+            'posisiton'  => 0
+        ];
+        $list = Db::name('banner')->where($where)->order('weigh desc,id desc')->autopage()->select();
+        $this->success(1,$list);
+    }
+
+    //商家钱包明细
+    public function money_log(){
+        $type = input('type',0);
+
+        $map = [
+            'user_id' => $this->auth->id,
+        ];
+        if($type){
+            $map['log_type'] = $type;
+        }
+
+        $list = Db::name('company_money_log')
+            ->field('id,log_type,change_value,remain,remark,createtime')
+            ->where($map)->order('id desc')->autopage()->select();
+        $list = $this->list_appen_logtext($list);
+
+        $this->success(1,$list);
+    }
+
+    //追加log_text
+    private function list_appen_logtext($list){
+        if(!empty($list)){
+            $conf = config('wallet.logtype');
+            foreach($list as $key => $val){
+                $list[$key]['log_text'] = isset($conf[$val['log_type']]) ? $conf[$val['log_type']] : '';
+            }
+        }
+        return $list;
+    }
+
+
+
+}

+ 117 - 0
application/api/controller/company/Takecash.php

@@ -0,0 +1,117 @@
+<?php
+
+namespace app\api\controller\company;
+
+use app\common\controller\Apic;
+use think\Db;
+
+/**
+ * 提现
+ */
+class Takecash extends Apic
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = '*';
+
+    public function _initialize()
+    {
+        parent::_initialize();
+    }
+
+    //提现配置
+    public function take_cash_config(){
+
+        $min_withdrawal_money = config('site.min_withdrawal_money') ? config('site.min_withdrawal_money') : 1;
+        $max_withdrawal_money = config('site.max_withdrawal_money') ? config('site.max_withdrawal_money') : 50000;
+        $data = [
+            'money' => model('walletcompany')->getwallet($this->auth->company_id,'money'),
+            'bank_name' => $this->auth->bank_name,
+            'bank_branchname' => $this->auth->bank_branchname,
+            'bank_account' => $this->auth->bank_account,
+            'bank_card' => $this->auth->bank_card,
+            'min' => $min_withdrawal_money,
+            'max' => $max_withdrawal_money,
+        ];
+
+        $this->success('success',$data);
+    }
+
+    //提现
+    public function take_cash(){
+
+        $money = floatval(input('money', 0, 'trim'));
+
+        //格式
+        if(empty($money) || $money <= 0){
+            $this->error('请输入正确提现金额');
+        }
+
+        //最低提现金额
+        $min_withdrawal_money = config('site.min_withdrawal_money') ? config('site.min_withdrawal_money') : 1;
+        $max_withdrawal_money = config('site.max_withdrawal_money') ? config('site.max_withdrawal_money') : 50000;
+        if ($money < $min_withdrawal_money) {
+            $this->error('最低提现金额' . $min_withdrawal_money . '元');
+        }
+        if ($money > $max_withdrawal_money) {
+            $this->error('最高提现金额' . $max_withdrawal_money . '元');
+        }
+
+        //查重
+        $check = Db::name('company_take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
+        if($check){
+            $this->error('您已经申请了提现,请等待审核');
+        }
+
+        //对比
+        $user_money = model('walletcompany')->getwallet($this->auth->id,'money');
+        if($money > $user_money){
+            $this->error('提现金额不能大于可提现余额');
+        }
+
+        //查询提现手续费百分比
+        $withdrawal_server_fee = (int)config('site.withdrawal_server_fee') ? : 0;
+        if ($withdrawal_server_fee < 0 || $withdrawal_server_fee >= 100) {
+            $this->error('提现手续费异常');
+        }
+
+        //
+        $real_money = bcdiv(bcmul($money,bcsub(100,$withdrawal_server_fee,2),2),100,2);
+        $data = [
+            'order_no' => createUniqueNo('T',$this->auth->id),
+            'user_id' => $this->auth->id,
+            'money' => $money,
+            'real_money' => $real_money,
+            'bank_name' => $this->auth->bank_name,
+            'bank_branchname' => $this->auth->bank_branchname,
+            'bank_account' => $this->auth->bank_account,
+            'bank_card' => $this->auth->bank_card,
+            'status' => 0,
+            'createtime' => time(),
+            'updatetime' => time(),
+        ];
+
+        Db::startTrans();
+        $logid = Db::name('company_take_cash')->insertGetId($data);
+        if (!$logid) {
+            Db::rollback();
+            $this->error('提现失败');
+        }
+
+        $rs_wallet = model('walletcompany')->lockChangeAccountRemain($this->auth->id,'money',-$money,101,'提现','company_take_cash',$logid);
+        if($rs_wallet['status'] === false){
+            Db::rollback();
+            $this->error($rs_wallet['msg']);
+        }
+
+        Db::commit();
+        $this->success('申请提现成功,请等待审核');
+    }
+
+    //提现记录
+    public function take_cash_log(){
+        $list = Db::name('company_take_cash')->where(['user_id'=>$this->auth->id])->autopage()->select();
+
+        $this->success('success',$list);
+    }
+
+}