Card.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * @author: xaboy<365615158@qq.com>
  4. * @day: 2017/11/11
  5. */
  6. namespace app\models\store;
  7. use app\models\system\SystemStore;
  8. use crmeb\services\PHPExcelService;
  9. use crmeb\traits\ModelTrait;
  10. use crmeb\basic\BaseModel;
  11. /**
  12. * 商品浏览分析
  13. * Class StoreVisit
  14. * @package app\admin\model\store
  15. */
  16. class Card extends BaseModel
  17. {
  18. /**
  19. * 数据表主键
  20. * @var string
  21. */
  22. protected $pk = 'id';
  23. /**
  24. * 模型名称
  25. * @var string
  26. */
  27. protected $name = 'card';
  28. use ModelTrait;
  29. /**
  30. * @param $where
  31. * @return array
  32. */
  33. public static function systemPage($where)
  34. {
  35. $model = new self;
  36. $model = $model->alias('s');
  37. if ($where['status'] != '') $model = $model->where('s.status', $where['status']);
  38. if ($where['name'] != '') $model = $model->where('s.name|s.code', 'LIKE', "%$where[name]%");
  39. $model = $model->page(bcmul($where['page'], $where['limit'], 0), $where['limit']);
  40. $model = $model->order('s.id desc');
  41. return self::page($model, function ($item) {
  42. if ($item['status'] == 0) {
  43. $item['start_name'] = '待赠送';
  44. } else if ($item['status'] == 1) {
  45. $item['start_name'] = '待核销';
  46. } else $item['start_name'] = '已使用';
  47. $item['store'] = $item['store_id'] ? SystemStore::where('id', $item['store_id'])->value('name') . '/' . $item['store_id'] : '--';
  48. $item['check_store'] = $item['check_store_id'] ? SystemStore::where('id', $item['check_store_id'])->value('name') . '/' . $item['check_store_id'] : '--';
  49. $item['add_time_text'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : '--';
  50. $item['send_time_text'] = $item['send_time'] ? date('Y-m-d H:i:s', $item['send_time']) : '--';
  51. $item['check_time_text'] = $item['check_time'] ? date('Y-m-d H:i:s', $item['check_time']) : '--';
  52. }, $where, $where['limit']);
  53. }
  54. public static function SaveExcel($where)
  55. {
  56. $model = new self;
  57. if ($where['status'] != '') $model = $model->where('s.status', $where['status']);
  58. if ($where['name'] != '') $model = $model->where('s.name|s.code', 'LIKE', "%$where[name]%");
  59. $list = $model->order('id desc')->select();
  60. count($list) && $list = $list->toArray();
  61. $excel = [];
  62. foreach ($list as $item) {
  63. if ($item['status'] == 0) {
  64. $item['start_name'] = '待赠送';
  65. } else if ($item['status'] == 1) {
  66. $item['start_name'] = '待核销';
  67. } else $item['start_name'] = '已使用';
  68. $excel[] = [
  69. $item['id'],
  70. $item['name'],
  71. $item['code'],
  72. $item['password'],
  73. $item['price'],
  74. $item['store_award'],
  75. $item['start_name'],
  76. ];
  77. }
  78. PHPExcelService::setExcelHeader(['编号', '标题', '卡号', '密码', '价格', '奖金', '状态'])
  79. ->setExcelTile('礼品卡导出', ' ', ' 生成时间:' . date('Y-m-d H:i:s', time()))
  80. ->setExcelContent($excel)
  81. ->ExcelSave();
  82. }
  83. public static function createCode()
  84. {
  85. do {
  86. $str = date('Y') . '-' . substr(time(), 6, 4) . rand(1000, 9999) . rand(1000, 9999);
  87. } while (self::be(['code' => $str]));
  88. return $str;
  89. }
  90. public static function createPassword()
  91. {
  92. return substr(md5(md5('lpk.zccy.rand' . rand(100000, 999999)) . rand(0, 100000)), 0, 16);
  93. }
  94. }