123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\admin\model\user;
- use service\SystemConfigService;
- use think\Db;
- use traits\ModelTrait;
- use basic\ModelBasic;
- use app\admin\model\user\MemberCard;
- /**
- * 会员卡批次 model
- * Class MemberCardBatch
- * @package app\admin\model\user
- */
- class MemberCardBatch extends ModelBasic
- {
- use ModelTrait;
- const fileLocation = 'public/qrcode/';
- /**批量获取批次卡
- * @param array $where
- * @return array|bool
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function getBatchList(array $where)
- {
- if (!is_array($where)) {
- return false;
- }
- $batch_where = array();
- if (isset($where['title']) && $where['title']) {
- $batch_where['title'] = ['like', '%' . $where['title']];
- }
- $data = self::where($batch_where)->order('id DESC')
- ->page((int)$where['page'], (int)$where['limit'])
- ->select()
- ->each(function ($item) {
- $item['create_time'] = ($item['create_time'] != 0 || $item['create_time']) ? date('Y-m-d H:i:s', $item['create_time']) : "";
- });
- $data = count((array)$data) ? $data->toArray() : [];
- $count = self::where($batch_where)->count();
- return compact('data', 'count');
- }
- /**
- * 生成会员卡批次二维码
- */
- public static function qrcodes_url($id = 0, $size = 5)
- {
- vendor('phpqrcode.phpqrcode');
- $urls = SystemConfigService::get('site_url') . '/';
- $url = $urls . 'wap/special/member_manage/type/2/bid/' . $id;
- $value = $url; //二维码内容
- $errorCorrectionLevel = 'H'; //容错级别
- $matrixPointSize = $size; //生成图片大小
- //生成二维码图片
- $filename = self::fileLocation . rand(10000000, 99999999) . '.png';
- \QRcode::png($value, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
- return $urls . $filename;
- }
- /**获取单条批次信息
- * @param $id
- * @return array|bool|false|\PDOStatement|string|\think\Model
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function getBatchOne($id)
- {
- if (!$id) {
- return false;
- }
- return self::where(['id' => $id])->find();
- }
- public static function getBatchAll(array $where)
- {
- if (!$where || !is_array($where)) {
- $where = array();
- }
- return self::where($where)->select();
- }
- /**增加批次表
- * @param array $insert_data
- * @return bool|int|string
- */
- public static function addBatch(array $insert_data)
- {
- if (!$insert_data) {
- return false;
- }
- return self::insertGetId($insert_data);
- }
- public function getCreateTimeAttr($time)
- {
- return $time;//返回create_time原始数据,不进行时间戳转换。
- }
- public static function delMemberCard($id)
- {
- $res = self::where('id', $id)->delete();
- $res1 = false;
- if ($res) {
- $res1 = MemberCard::where('card_batch_id', $id)->delete();
- }
- $res2 = $res && $res1;
- return $res2;
- }
- }
|