WechatPlan.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class WechatPlan extends Model
  5. {
  6. // 自动写入时间戳字段
  7. protected $autoWriteTimestamp = 'int';
  8. // 定义时间戳字段名
  9. protected $createTime = 'createtime';
  10. protected $updateTime = 'updatetime';
  11. public static function getNewCode()
  12. {
  13. do {
  14. list($msec, $sec) = explode(' ', microtime());
  15. $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
  16. $orderId = 'qy' . $msectime . mt_rand(10000, 99999);
  17. } while (self::where(['order_id' => $orderId])->find());
  18. return $orderId;
  19. }
  20. public static function lst($where)
  21. {
  22. $model = new self;
  23. $xwhere = null;
  24. $order = "id desc";
  25. if (isset($where['cid']) && $where['cid'] > 0) $xwhere['cid'] = $where['cid'];
  26. if (isset($where['plan_id']) && $where['plan_id'] > 0) $xwhere['plan_id'] = $where['plan_id'];
  27. if (isset($where['price']) && $where['price'] > 0) $xwhere['price'] = $where['price'];
  28. // if (isset($where['paid']) && $where['paid'] > -1) $xwhere['paid'] = $where['paid'];
  29. // if (isset($where['help_id']) && $where['help_id'] > -1) $xwhere['help_id'] = $where['help_id'];
  30. // if (isset($where['order']) && $where['order'] != '') $order = $where['order'];
  31. // if (isset($where['key']) && $where['key'] != '') $xwhere['name|contact|tel'] = ['like', "%{$where['key']}%"];
  32. $data = $model->where($xwhere)->order($order)->page($where['page'], $where['limit'])->select();
  33. $count = $model->where($xwhere)->count();
  34. return compact('count', 'data');
  35. }
  36. public static function read($where)
  37. {
  38. $model = new self;
  39. $xwhere = null;
  40. $order = "id desc";
  41. if (isset($where['id']) && $where['id'] > 0) $xwhere['id'] = $where['id'];
  42. $data = $model->where($xwhere)->order($order)->page($where['page'], $where['limit'])->select();
  43. // $count = $model->where($xwhere)->count();
  44. return $data;
  45. }
  46. }