MemberCardBatch.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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\MemberCard;
  17. /**
  18. * 会员卡批次 model
  19. * Class MemberCardBatch
  20. * @package app\admin\model\user
  21. */
  22. class MemberCardBatch extends ModelBasic
  23. {
  24. use ModelTrait;
  25. const fileLocation = 'public/qrcode/';
  26. /**批量获取批次卡
  27. * @param array $where
  28. * @return array|bool
  29. * @throws \think\Exception
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. * @throws \think\exception\DbException
  33. */
  34. public static function getBatchList(array $where)
  35. {
  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. {
  58. vendor('phpqrcode.phpqrcode');
  59. $urls = SystemConfigService::get('site_url') . '/';
  60. $url = $urls . 'wap/special/member_manage/type/2/bid/' . $id;
  61. $value = $url; //二维码内容
  62. $errorCorrectionLevel = 'H'; //容错级别
  63. $matrixPointSize = $size; //生成图片大小
  64. //生成二维码图片
  65. $filename = self::fileLocation . rand(10000000, 99999999) . '.png';
  66. \QRcode::png($value, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
  67. return $urls . $filename;
  68. }
  69. /**获取单条批次信息
  70. * @param $id
  71. * @return array|bool|false|\PDOStatement|string|\think\Model
  72. * @throws \think\db\exception\DataNotFoundException
  73. * @throws \think\db\exception\ModelNotFoundException
  74. * @throws \think\exception\DbException
  75. */
  76. public static function getBatchOne($id)
  77. {
  78. if (!$id) {
  79. return false;
  80. }
  81. return self::where(['id' => $id])->find();
  82. }
  83. public static function getBatchAll(array $where)
  84. {
  85. if (!$where || !is_array($where)) {
  86. $where = array();
  87. }
  88. return self::where($where)->select();
  89. }
  90. /**增加批次表
  91. * @param array $insert_data
  92. * @return bool|int|string
  93. */
  94. public static function addBatch(array $insert_data)
  95. {
  96. if (!$insert_data) {
  97. return false;
  98. }
  99. return self::insertGetId($insert_data);
  100. }
  101. public function getCreateTimeAttr($time)
  102. {
  103. return $time;//返回create_time原始数据,不进行时间戳转换。
  104. }
  105. public static function delMemberCard($id)
  106. {
  107. $res = self::where('id', $id)->delete();
  108. $res1 = false;
  109. if ($res) {
  110. $res1 = MemberCard::where('card_batch_id', $id)->delete();
  111. }
  112. $res2 = $res && $res1;
  113. return $res2;
  114. }
  115. }