SpecialBatch.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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\ump;
  12. use think\Db;
  13. use traits\ModelTrait;
  14. use basic\ModelBasic;
  15. use app\admin\model\special\Special;
  16. use app\admin\model\ump\SpecialExchange;
  17. /**
  18. * 活动批次 model
  19. * Class MemberCard
  20. * @package app\admin\model\ump
  21. */
  22. class SpecialBatch extends ModelBasic
  23. {
  24. use ModelTrait;
  25. /**增加批次表
  26. * @param array $insert_data
  27. * @return bool|int|string
  28. */
  29. public static function addBatch(array $insert_data)
  30. {
  31. if (!$insert_data) {
  32. return false;
  33. }
  34. return self::insertGetId($insert_data);
  35. }
  36. /**批量获取活动批次卡
  37. * @param array $where
  38. * @return array|bool
  39. * @throws \think\Exception
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. * @throws \think\exception\DbException
  43. */
  44. public static function getBatchList(array $where)
  45. {
  46. if (!is_array($where)) {
  47. return false;
  48. }
  49. $batch_where = array();
  50. if (isset($where['title']) && $where['title']) {
  51. $batch_where['title'] = ['like', '%' . $where['title']];
  52. }
  53. if (isset($where['special_id']) && $where['special_id']) {
  54. $batch_where['special_id'] = $where['special_id'];
  55. }
  56. $time['data'] = '';
  57. if ($where['start_time'] != '' && $where['end_time'] != '') {
  58. $time['data'] = $where['start_time'] . ' - ' . $where['end_time'];
  59. }
  60. $data = self::getModelTime($time)->where($batch_where)->order('id DESC')
  61. ->page((int)$where['page'], (int)$where['limit'])
  62. ->select()
  63. ->each(function ($item) {
  64. $item['add_time'] = ($item['add_time'] != 0 || $item['add_time']) ? date('Y-m-d H:i:s', $item['add_time']) : '';
  65. $item['special_title'] = Special::where('id', $item['special_id'])->value('title');
  66. });
  67. $data = count((array)$data) ? $data->toArray() : [];
  68. $count = self::where($batch_where)->count();
  69. return compact('data', 'count');
  70. }
  71. public function getCreateTimeAttr($time)
  72. {
  73. return $time;//返回create_time原始数据,不进行时间戳转换。
  74. }
  75. public static function getBatchAll(array $where)
  76. {
  77. if (!$where || !is_array($where)) {
  78. $where = array();
  79. }
  80. return self::where($where)->select();
  81. }
  82. public static function delSpecialBatch($id)
  83. {
  84. $res = self::where('id', $id)->delete();
  85. $res1 = false;
  86. if ($res) {
  87. $res1 = SpecialExchange::where('card_batch_id', $id)->delete();
  88. }
  89. $res2 = $res && $res1;
  90. return $res2;
  91. }
  92. }