WIN-2308041133\Administrator 1 år sedan
förälder
incheckning
136f282d01

+ 116 - 0
application/admin/model/LaveMonth.php

@@ -0,0 +1,116 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+
+class LaveMonth extends Model
+{
+
+    
+
+    
+
+    // 表名
+    protected $name = 'lave_month';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'int';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+        'is_open_text',
+        'is_ticket_text',
+        'paid_text',
+        'pay_type_text',
+        'paytime_text',
+        'type_text'
+    ];
+    
+
+    
+    public function getIsOpenList()
+    {
+        return ['0' => __('Is_open 0'), '1' => __('Is_open 1')];
+    }
+
+    public function getIsTicketList()
+    {
+        return ['0' => __('Is_ticket 0'), '1' => __('Is_ticket 1')];
+    }
+
+    public function getPaidList()
+    {
+        return ['0' => __('Paid 0'), '1' => __('Paid 1')];
+    }
+
+    public function getPayTypeList()
+    {
+        return ['0' => __('Pay_type 0'), '1' => __('Pay_type 1'), '2' => __('Pay_type 2'), '3' => __('Pay_type 3'), '4' => __('Pay_type 4')];
+    }
+
+    public function getTypeList()
+    {
+        return ['0' => __('Type 0'), '1' => __('Type 1')];
+    }
+
+
+    public function getIsOpenTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['is_open']) ? $data['is_open'] : '');
+        $list = $this->getIsOpenList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getIsTicketTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['is_ticket']) ? $data['is_ticket'] : '');
+        $list = $this->getIsTicketList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getPaidTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['paid']) ? $data['paid'] : '');
+        $list = $this->getPaidList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getPayTypeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
+        $list = $this->getPayTypeList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getPaytimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+
+    public function getTypeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
+        $list = $this->getTypeList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+    protected function setPaytimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+
+}

+ 2 - 2
application/admin/model/WechatPlanRecord.php

@@ -62,8 +62,8 @@ class WechatPlanRecord extends Model
 //        if (isset($where['category_id']) && $where['category_id'] > 0) $xwhere['category_id'] = $where['category_id'];
         $data = $model->where($xwhere)->where('is_signing',0)->order($order)->select();
         $count = $model->where($xwhere)->count();
-        $lave = new Lave();
-        $list = $lave->where('user_id', $data[0]['uid'])->where('cid',$data[0]['cid'])->where('order_name', $data[0]['order_name'])->select();
+        $laveMonth = new LaveMonth();
+        $list = $laveMonth->where('user_id', $data[0]['uid'])->where('cid',$data[0]['cid'])->where('order_name', $data[0]['order_name'])->select();
         return compact('count', 'data','list');
     }
 }

+ 12 - 11
application/api/controller/Lave.php

@@ -7,6 +7,7 @@ use app\admin\model\WechatPlan;
 use app\admin\model\WechatPlanRecord;
 use app\common\controller\Api;
 use app\common\model\{Category, Lave as LaveModel, User};
+use app\common\model\LaveMonth as LaveMonthModel;
 use liuniu\repositories\LaveRepository;
 use liuniu\UtilService;
 use liuniu\WechatService;
@@ -154,7 +155,7 @@ class Lave extends Api
                 ['user_id', $this->auth->getUserinfo()['id']],
 //                ['user_id', 0],
                 ['order_name', ''],
-                ['category_id', 0],
+//                ['category_id', 0],
                 ['amount', 0],
                 ['name', ''],
                 ['contact', ''],
@@ -171,7 +172,7 @@ class Lave extends Api
         );
         $where1 = $where;
         unset($where1['from']);
-        $where1['order_id'] = LaveModel::getNewOrderId();
+        $where1['order_id'] = LaveMonthModel::getNewOrderId();
         $contract_display_account = User::where('id', $where1['user_id'])->value('nickname');
         if (empty($contract_display_account)){
             $this->error('用户不存在!');
@@ -180,17 +181,17 @@ class Lave extends Api
         if (cache('lave_' . $where['user_id'])) $this->error('正在处理中');
         @file_put_contents("lave.txt", json_encode($where1));
         $plan_id=$where1['plan_id'];
-        unset($where1['plan_id']);
-        $order = LaveModel::create($where1);
+//        unset($where1['plan_id']);
+        $order = LaveMonthModel::create($where1);
         $where1['contract_code'] = WechatPlanRecord::getNewCode();
         $where1['contract_display_account']=$contract_display_account;
         cache('lave_' . $where['user_id'], '1', 10);
-        if (!$order) $this->error(LaveModel::getErrorInfo());
+        if (!$order) $this->error(LaveMonthModel::getErrorInfo());
         $orderId = $order['order_id'];
         $info = compact('orderId');
         $order['plan_id'] = $plan_id;
         if ($orderId) {
-            $orderInfo = LaveModel::where('order_id', $orderId)->find();
+            $orderInfo = LaveMonthModel::where('order_id', $orderId)->find();
             if (!$orderInfo || !isset($orderInfo['paid'])) $this->error('支付订单不存在!');
             if ($orderInfo['paid']) $this->error('支付已支付!');
 //          创建签约
@@ -204,7 +205,7 @@ class Lave extends Api
                 'contract_display_account'=>$where1['contract_display_account'],
                 'is_open'=>$where1['is_open'],
                 'tel'=>$where1['tel'],
-                'category_id'=>$where1['category_id'],
+//                'category_id'=>$where1['category_id'],
                 'order_name'=>$where1['order_name'],
             ];
             $record=WechatPlanRecord::create($plan_record);
@@ -230,7 +231,7 @@ class Lave extends Api
             }
             return $this->success('订单创建成功', $info);
 
-        } else $this->error(LaveModel::getErrorInfo());
+        } else $this->error(LaveMonthModel::getErrorInfo());
     }
     /**
      * 签约订单支付
@@ -246,7 +247,7 @@ class Lave extends Api
             ['from', 'weixin']
         ], $request, true);
         if (!$uni) $this->error('参数错误!');
-        $order = LaveModel::where('cid', $this->cid)->where('order_id', $uni)->find();
+        $order = LaveMonthModel::where('cid', $this->cid)->where('order_id', $uni)->find();
         if (!$order)
             $this->error('订单不存在!');
         if ($order['paid'])
@@ -286,7 +287,7 @@ class Lave extends Api
             $cid=$v['cid'];
 //            if ($this->querySign($cid,$v['uid'],$v['plan_id'],$v['contract_code'])){
                 $arr['mch_id'] =Company::where('id', $cid)->value('pay_weixin_mchid');
-                $arr['out_trade_no']=LaveModel::getNewOrderId();
+                $arr['out_trade_no']=LaveMonthModel::getNewOrderId();
                 $arr['total_fee'] = $v['price'];
 //            $arr['trade_type'] = 'PAP';
                 $arr['contract_id'] = Company::where('id', $cid)->value('contract_id');
@@ -305,7 +306,7 @@ class Lave extends Api
                 $where1['is_ticket']='0';
                 $where1['type']='0';
                 $where1['help_id']='0';
-                $order = LaveModel::create($where1);
+                $order = LaveMonthModel::create($where1);
 //            }
         }
     }

+ 165 - 0
application/common/model/LaveMonth.php

@@ -0,0 +1,165 @@
+<?php
+
+namespace app\common\model;
+
+use liuniu\BaseModel;
+use think\Exception;
+use think\Model;
+
+
+class LaveMonth extends BaseModel
+{
+
+    // 表名
+    protected $name = 'lave_month';
+
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'int';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+        'is_open_text',
+        'is_ticket_text',
+        'paid_text',
+        'pay_type_text',
+        'paytime_text',
+        'type_text'
+    ];
+
+
+    public function getIsOpenList()
+    {
+        return ['0' => __('Is_open 0'), '1' => __('Is_open 1')];
+    }
+
+    public function getIsTicketList()
+    {
+        return ['0' => __('Is_ticket 0'), '1' => __('Is_ticket 1')];
+    }
+
+    public function getPaidList()
+    {
+        return ['0' => __('Paid 0'), '1' => __('Paid 1')];
+    }
+
+    public function getPayTypeList()
+    {
+        return ['0' => __('Pay_type 0'), '1' => __('Pay_type 1'), '2' => __('Pay_type 2'), '3' => __('Pay_type 3'), '4' => __('Pay_type 4')];
+    }
+
+    public function getTypeList()
+    {
+        return ['0' => __('Type 0'), '1' => __('Type 1')];
+    }
+
+
+    public function getIsOpenTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['is_open']) ? $data['is_open'] : '');
+        $list = $this->getIsOpenList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getIsTicketTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['is_ticket']) ? $data['is_ticket'] : '');
+        $list = $this->getIsTicketList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getPaidTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['paid']) ? $data['paid'] : '');
+        $list = $this->getPaidList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getPayTypeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
+        $list = $this->getPayTypeList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getPaytimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+
+    public function getTypeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
+        $list = $this->getTypeList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+    protected function setPaytimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+    public static function lst($where)
+    {
+        $model = new self;
+        $xwhere = null;
+        $order = "id desc";
+        if (isset($where['cid']) && $where['cid'] > 0) $xwhere['cid'] = $where['cid'];
+        if (isset($where['user_id']) && $where['user_id'] > 0) $xwhere['user_id'] = $where['user_id'];
+        if (isset($where['category_id']) && $where['category_id'] > 0) $xwhere['category_id'] = $where['category_id'];
+        if (isset($where['paid']) && $where['paid'] > -1) $xwhere['paid'] = $where['paid'];
+        if (isset($where['help_id']) && $where['help_id'] > -1) $xwhere['help_id'] = $where['help_id'];
+        if (isset($where['order']) && $where['order'] != '') $order = $where['order'];
+        if (isset($where['key']) && $where['key'] != '') $xwhere['name|contact|tel'] = ['like', "%{$where['key']}%"];
+        $data = $model->where($xwhere)->order($order)->page($where['page'], $where['limit'])->select();
+        $count = $model->where($xwhere)->count();
+        return compact('count', 'data');
+    }
+
+    public static function lave_create($where)
+    {
+        try {
+            if ($where['cid'] == 0 || $where['user_id'] == 0 || $where['amount'] <= 0 || empty($where['name']) || empty($where['tel'])) return self::setErrorInfo('请核对信息');
+            if ($where['type'] == 1 && $where['contact'] == '') return self::setErrorInfo('请核对信息');
+            $where['order_id'] = self::getNewOrderId();
+            $rs = self::create($where);
+            return $rs;
+        } catch (Exception $e) {
+            return self::setErrorInfo($e->getMessage());
+        }
+    }
+
+    public static function getNewOrderId()
+    {
+        do {
+            list($msec, $sec) = explode(' ', microtime());
+            $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
+            $orderId = 'yj' . $msectime . mt_rand(10000, 99999);
+        } while (self::where(['order_id' => $orderId])->find());
+        return $orderId;
+    }
+
+    public static function paySuccess($cid, $order_id)
+    {
+        $max_sn = self::where('cid', $cid)->order('SN DESC')->value('SN');
+        if ($max_sn) {
+            $no = intval(explode("_", $max_sn)[1]) + 1;
+        } else {
+            $no = 1;
+        }
+        $SN = $cid . "_" . str_pad($no, 8, '0', STR_PAD_LEFT);
+        $res = self::where('order_id', $order_id)->where('cid', $cid)->update(['paid' => 1, 'paytime' => time(), "SN" => $SN]);//订单改为支付
+        return false !== $res;
+    }
+
+}