HbController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace mall\controllers;
  3. use Yii;
  4. use common\components\util;
  5. use bizHd\hb\classes\HbClass;
  6. class HbController extends BaseController
  7. {
  8. //优惠券列表 ssh 2019.12.11
  9. public function actionList()
  10. {
  11. $get = Yii::$app->request->get();
  12. $where = [];
  13. $where['t.userId'] = $this->userId;
  14. $status = $get['status'] ?? '';
  15. if ($status != '') {
  16. $where['t.status'] = $get['status'];
  17. }
  18. $respond = HbClass::getHbList(['t.*', 's.merchantName', 's.shopName'], $where);
  19. if (!empty($respond['list'])) {
  20. foreach ($respond['list'] as &$v) {
  21. $v['customName'] = $v['custom']['name'] ?? '';
  22. if ($v['status'] == 0 && $v['endTime'] < time()) {
  23. //发现红包已过期,需要作废,多有处作废操作,搜索关键词 cancellation_hb
  24. $id = $v['id'];
  25. HbClass::updateById($id, ['status' => -1]);
  26. }
  27. }
  28. }
  29. util::success($respond);
  30. }
  31. // 单个门店下所有可用红包
  32. public function actionAvailableHb()
  33. {
  34. $where = [];
  35. $where['customId'] = $this->customId;
  36. $where['status'] = 0;
  37. $where['beginTime<='] = time();
  38. $list = HbClass::getAllByCondition($where, 'id DESC');
  39. //已经过期的就不再显示,并且作废,多有处作废操作,搜索关键词 cancellation_hb
  40. if (!empty($list)) {
  41. foreach ($list as $k => $v) {
  42. if ($v['status'] == 0 && $v['endTime'] < time()) {
  43. unset($list[$k]);
  44. $id = $v['id'];
  45. HbClass::updateById($id, ['status' => -1]);
  46. }
  47. }
  48. }
  49. util::success($list);
  50. }
  51. }