MemberCardBatch.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\user;
  12. use service\SystemConfigService;
  13. use think\Db;
  14. use traits\ModelTrait;
  15. use basic\ModelBasic;
  16. use app\admin\model\user\User;
  17. use app\admin\model\user\UserBill;
  18. use app\admin\model\user\Group as GroupModel;
  19. /**
  20. * 会员卡批次 model
  21. * Class User
  22. * @package app\admin\model\user
  23. */
  24. class MemberCardBatch extends ModelBasic
  25. {
  26. use ModelTrait;
  27. /**批量获取批次卡
  28. * @param array $where
  29. * @return array|bool
  30. * @throws \think\Exception
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. * @throws \think\exception\DbException
  34. */
  35. public static function getBatchList(array $where){
  36. if (!is_array($where)) {
  37. return false;
  38. }
  39. $batch_where = array();
  40. if (isset($where['title']) && $where['title']){
  41. $batch_where['title'] = ['like','%'.$where['title']];
  42. }
  43. $data = self::where($batch_where)->order('id DESC')
  44. ->page((int)$where['page'], (int)$where['limit'])
  45. ->select()
  46. ->each(function ($item){
  47. $item['create_time'] = ($item['create_time'] != 0 || $item['create_time']) ? date('Y-m-d H:i:s', $item['create_time']) : "";
  48. });
  49. $data = count((array)$data) ? $data->toArray() : [];
  50. $count = self::where($batch_where)->count();
  51. return compact('data','count');
  52. }
  53. /**
  54. * 生成会员卡批次二维码
  55. */
  56. public static function qrcodes_url($id=0,$size=5){
  57. vendor('phpqrcode.phpqrcode');
  58. $urls=SystemConfigService::get('site_url').'/';
  59. $url=$urls.'wap/special/member_manage/type/2/bid/'.$id;
  60. $value = $url; //二维码内容
  61. $errorCorrectionLevel = 'H'; //容错级别
  62. $matrixPointSize = $size; //生成图片大小
  63. //生成二维码图片
  64. $filename = 'public/qrcode/'.rand(10000000,99999999).'.png';
  65. \QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, 2);
  66. return $urls.$filename;
  67. }
  68. /**获取单条批次信息
  69. * @param $id
  70. * @return array|bool|false|\PDOStatement|string|\think\Model
  71. * @throws \think\db\exception\DataNotFoundException
  72. * @throws \think\db\exception\ModelNotFoundException
  73. * @throws \think\exception\DbException
  74. */
  75. public static function getBatchOne($id)
  76. {
  77. if (!$id) {
  78. return false;
  79. }
  80. return self::where(['id' => $id])->find();
  81. }
  82. public static function getBatchAll(array $where)
  83. {
  84. if (!$where || !is_array($where)) {
  85. $where = array();
  86. }
  87. return self::where($where)->select();
  88. }
  89. /**增加批次表
  90. * @param array $insert_data
  91. * @return bool|int|string
  92. */
  93. public static function addBatch(array $insert_data)
  94. {
  95. if (!$insert_data) {
  96. return false;
  97. }
  98. return self::insertGetId($insert_data);
  99. }
  100. public function getCreateTimeAttr($time)
  101. {
  102. return $time;//返回create_time原始数据,不进行时间戳转换。
  103. }
  104. }