DiyController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace addons\BlindBox\backend\controllers;
  3. use addons\BlindBox\common\models\BlindBoxGoods;
  4. use common\enums\AddonsEnum;
  5. use common\enums\StatusEnum;
  6. use common\models\common\AddonsMarketingSetting;
  7. /**
  8. * 默认控制器
  9. *
  10. * Class DefaultController
  11. * @package addons\BlindBox\backend\controllers
  12. */
  13. class DiyController extends BaseController
  14. {
  15. /**
  16. * 首页
  17. *
  18. * @return string
  19. */
  20. public function actionIndex()
  21. {
  22. if (\Yii::$app->request->isAjax) {
  23. if (\Yii::$app->request->isPost) {
  24. $params = \Yii::$app->request->post();
  25. $res = \Yii::$app->services->validate->validate($params, [
  26. [['content'], 'required'],
  27. ]);
  28. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  29. $params['mall_id'] = $this->mall_id;
  30. $params['addons_name'] = AddonsEnum::ADDONS_NAME_BLIND_BOX;
  31. $res = AddonsMarketingSetting::setData($params);
  32. if ($res == false) return $this->error(AddonsMarketingSetting::getStaticError());
  33. return $this->success('操作成功', []);
  34. }
  35. if (\Yii::$app->request->isGet) {
  36. $params['mall_id'] = $this->mall_id;
  37. $params['addons_name'] = AddonsEnum::ADDONS_NAME_BLIND_BOX;
  38. $params['status'] = StatusEnum::ENABLED;
  39. $res = AddonsMarketingSetting::findOne($params);
  40. if ($res == false) return $this->success('操作成功', $data ?? []);
  41. $data = $res->toArray();
  42. $content = json_decode($data['content'], true);
  43. if (!empty($content)) {
  44. // $active_data = array_pop($content);
  45. // $active_ids = [];
  46. if (!empty($active_data['data']['goods'])) {
  47. // foreach ($active_data['data']['goods'] as $item) {
  48. // $active_ids[] = $item['params']['id'];
  49. // }
  50. // $list = BargainActive::lists(['where' => [
  51. // ['id' => $active_ids],
  52. // ['status' => StatusEnum::ENABLED],
  53. // ['active_status' => [BargainEnum::ACTIVE_HANDING]],
  54. // ['mall_id' => $this->mall_id]], 'select' => 'id']
  55. // );
  56. // $active_id_arr = array_column($list, 'id');//没有被删除的活动id
  57. // $goods_data = [];
  58. // foreach ($active_data['data']['goods'] as $item) {
  59. // if (in_array($item['params']['id'], $active_id_arr)) $goods_data[] = $item;
  60. // }
  61. // $active_data['data']['goods'] = $goods_data;
  62. // $content[] = $active_data;
  63. // $data['content'] = json_encode($content);
  64. }
  65. }
  66. return $this->success('操作成功', $data ?? []);
  67. }
  68. }
  69. return $this->render('index', [
  70. ]);
  71. }
  72. public function actionCheckGoodsList()
  73. {
  74. $params = \Yii::$app->request->get();
  75. $goods_id = json_decode($params['goods_id'], true);
  76. $list = BlindBoxGoods::getGoodsList($this->mall_id,$goods_id);
  77. return $this->success('操作成功', $list);
  78. }
  79. }