StoreCoupon.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2018/01/22
  6. */
  7. namespace app\models\store;
  8. use crmeb\basic\BaseModel;
  9. use crmeb\traits\ModelTrait;
  10. /**
  11. * TODO 优惠券Model
  12. * Class StoreCoupon
  13. * @package app\models\store
  14. */
  15. class StoreCoupon extends BaseModel
  16. {
  17. /**
  18. * 数据表主键
  19. * @var string
  20. */
  21. protected $pk = 'id';
  22. /**
  23. * 模型名称
  24. * @var string
  25. */
  26. protected $name = 'store_coupon';
  27. use ModelTrait;
  28. public function getTypeAttr($value)
  29. {
  30. $status = [0=>'通用券',1=>'品类券',2=>'商品券'];
  31. return $status[$value];
  32. }
  33. /**
  34. * @param $where
  35. * @return array
  36. */
  37. public static function systemPage($where)
  38. {
  39. $model = new self;
  40. if ($where['mer_id'] != '') $model = $model->where('mer_id', $where['mer_id']);
  41. if ($where['status'] != '') $model = $model->where('status', $where['status']);
  42. if ($where['title'] != '') $model = $model->where('title', 'LIKE', "%$where[title]%");
  43. $model = $model->where('is_del', 0);
  44. $count = $model->count();
  45. $model = $model->order('sort desc,id desc');
  46. $list = $model->page((int)$where['page'], (int)$where['limit'])->select();
  47. return compact('count', 'list');
  48. }
  49. /**
  50. * 修改状态
  51. * @param $id
  52. * @return bool
  53. */
  54. public static function editIsDel($id)
  55. {
  56. $data['status'] = 0;
  57. self::beginTrans();
  58. $res1 = self::edit($data, $id);
  59. $res2 = false !== StoreCouponUser::where('cid', $id)->update(['is_fail' => 1]);
  60. $res3 = false !== StoreCouponIssue::where('cid', $id)->update(['status' => -1]);
  61. $res = $res1 && $res2 && $res3;
  62. self::checkTrans($res);
  63. return $res;
  64. }
  65. /**
  66. * 发送优惠券列表
  67. * @param $where
  68. * @return array
  69. */
  70. public static function systemPageCoupon($where)
  71. {
  72. $model = new self;
  73. if ($where['status'] != '') $model = $model->where('status', $where['status']);
  74. if ($where['title'] != '') $model = $model->where('title', 'LIKE', "%$where[title]%");
  75. if ($where['mer_id'] != '') $model = $model->where('mer_id', $where['mer_id']);
  76. $model = $model->where('is_del', 0);
  77. $model = $model->where('status', 1);
  78. $model = $model->order('sort desc,id desc');
  79. $count = $model->count();
  80. $list = $model->page((int)$where['page'], (int)$where['limit'])->select();
  81. return compact('count', 'list');
  82. }
  83. }