StoreCoupon.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * @author: xaboy<365615158@qq.com>
  4. * @day: 2017/11/11
  5. */
  6. namespace app\admin\model\ump;
  7. use crmeb\services\FormBuilder as Form;
  8. use crmeb\traits\ModelTrait;
  9. use crmeb\basic\BaseModel;
  10. use think\facade\Route as Url;
  11. use app\admin\model\store\StoreCategory as CategoryModel;
  12. /**
  13. * Class StoreCategory
  14. * @package app\admin\model\store
  15. */
  16. class StoreCoupon extends BaseModel
  17. {
  18. /**
  19. * 数据表主键
  20. * @var string
  21. */
  22. protected $pk = 'id';
  23. /**
  24. * 模型名称
  25. * @var string
  26. */
  27. protected $name = 'store_coupon';
  28. use ModelTrait;
  29. /**
  30. * @param $where
  31. * @return array
  32. */
  33. public static function systemPage($where)
  34. {
  35. $model = new self;
  36. if ($where['status'] != '') $model = $model->where('status', $where['status']);
  37. if ($where['type'] != '') $model = $model->where('type', $where['type']);
  38. if ($where['title'] != '') $model = $model->where('title', 'LIKE', "%$where[title]%");
  39. // if($where['is_del'] != '') $model = $model->where('is_del',$where['is_del']);
  40. $model = $model->where('is_del', 0);
  41. $model = $model->order('id desc');
  42. return self::page($model, $where);
  43. }
  44. /**
  45. * @param $where
  46. * @return array
  47. */
  48. public static function systemPageCoupon($where)
  49. {
  50. $model = new self;
  51. if ($where['status'] != '') $model = $model->where('status', $where['status']);
  52. if ($where['title'] != '') $model = $model->where('title', 'LIKE', "%$where[title]%");
  53. // if($where['is_del'] != '') $model = $model->where('is_del',$where['is_del']);
  54. $model = $model->where('is_del', 0);
  55. $model = $model->where('status', 1);
  56. $model = $model->order('sort desc,id desc');
  57. return self::page($model, $where);
  58. }
  59. public static function editIsDel($id)
  60. {
  61. $data['status'] = 0;
  62. self::beginTrans();
  63. $res1 = self::edit($data, $id);
  64. $res2 = false !== StoreCouponUser::where('cid', $id)->update(['is_fail' => 1]);
  65. $res3 = false !== StoreCouponIssue::where('cid', $id)->update(['status' => -1]);
  66. $res = $res1 && $res2 && $res3;
  67. self::checkTrans($res);
  68. return $res;
  69. }
  70. /**
  71. * 品类券
  72. * @param $tab_id
  73. * @return array
  74. * @throws \FormBuilder\exception\FormBuilderException
  75. */
  76. public static function createClassRule($tab_id)
  77. {
  78. $formbuider = [];
  79. $formbuider[] = Form::select('category_id', '选择品类')->setOptions(function () {
  80. $list = CategoryModel::getTierList(null, 1);
  81. $menus = [];
  82. foreach ($list as $menu) {
  83. $menus[] = ['value' => $menu['id'], 'label' => $menu['html'] . $menu['cate_name']];
  84. }
  85. return $menus;
  86. })->filterable(1)->col(12);
  87. return $formbuider;
  88. }
  89. /**
  90. * 商品券
  91. * @param $tab_id
  92. * @return array
  93. * @throws \FormBuilder\exception\FormBuilderException
  94. */
  95. public static function createProductRule($tab_id)
  96. {
  97. $formbuider = [];
  98. $formbuider[] = Form::frameImages('image', '商品', Url::buildUrl('admin/ump.StoreCoupon/select', array('fodder' => 'image')))->icon('plus')->width('100%')->height('500px');
  99. $formbuider[] = Form::hidden('product_id', 0);
  100. return $formbuider;
  101. }
  102. }