You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zhishifufei_php/application/admin/model/ump/SpecialBatch.php

104 lines
3.4 KiB

10 months ago
<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\admin\model\ump;
use think\Db;
use traits\ModelTrait;
use basic\ModelBasic;
use app\admin\model\special\Special;
use app\admin\model\ump\SpecialExchange;
/**
* 活动批次 model
* Class MemberCard
* @package app\admin\model\ump
*/
class SpecialBatch extends ModelBasic
{
use ModelTrait;
/**增加批次表
* @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);
}
/**批量获取活动批次卡
* @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']];
}
if (isset($where['special_id']) && $where['special_id']) {
$batch_where['special_id'] = $where['special_id'];
}
$time['data'] = '';
if ($where['start_time'] != '' && $where['end_time'] != '') {
$time['data'] = $where['start_time'] . ' - ' . $where['end_time'];
}
$data = self::getModelTime($time)->where($batch_where)->order('id DESC')
->page((int)$where['page'], (int)$where['limit'])
->select()
->each(function ($item) {
$item['add_time'] = ($item['add_time'] != 0 || $item['add_time']) ? date('Y-m-d H:i:s', $item['add_time']) : '';
$item['special_title'] = Special::where('id', $item['special_id'])->value('title');
});
$data = count((array)$data) ? $data->toArray() : [];
$count = self::where($batch_where)->count();
return compact('data', 'count');
}
public function getCreateTimeAttr($time)
{
return $time;//返回create_time原始数据,不进行时间戳转换。
}
public static function getBatchAll(array $where)
{
if (!$where || !is_array($where)) {
$where = array();
}
return self::where($where)->select();
}
public static function delSpecialBatch($id)
{
$res = self::where('id', $id)->delete();
$res1 = false;
if ($res) {
$res1 = SpecialExchange::where('card_batch_id', $id)->delete();
}
$res2 = $res && $res1;
return $res2;
}
}