AddonsController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace addons\Store\client\controllers;
  3. use addons\HuifuPay\common\service\HuifuBillShareService;
  4. use addons\Store\common\models\StoreAddons;
  5. use common\enums\AddonsEnum;
  6. use common\enums\StatusEnum;
  7. use common\models\mall\MallAddons;
  8. use Yii;
  9. /**
  10. * 商品控制器
  11. * @Author bing
  12. * @DateTime 2021-08-16 13:12:44
  13. * @copyright: Copyright (c) 2020 广东七件事集团
  14. */
  15. class AddonsController extends BaseController
  16. {
  17. public $enableCsrfValidation = false;
  18. /**
  19. * 应用
  20. * @Author:lun
  21. * @Date:2023-12-19 14:54
  22. * @Copyright:copyright(c)2023 广东七件事集团
  23. * @return mixed|string|null
  24. */
  25. public function actionIndex(){
  26. $request = Yii::$app->request;
  27. if ($request->isAjax && $request->isGet) {
  28. $get = Yii::$app->request->get();
  29. $rules = [
  30. [['keyword'], 'string'],
  31. ];
  32. $res = Yii::$app->services->validate->validate($get, $rules);
  33. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  34. $where = [];
  35. isset($get['keyword']) && $where[] = ['=', 'title', $get['keyword']];
  36. $where[] = ['=', 'status', StatusEnum::ENABLED];
  37. $order = 'id asc';
  38. $params = array('where' => $where, 'order' => $order);
  39. $data['list'] = StoreAddons::lists($params, true);
  40. if (empty($data['list'])) return $this->error('获取失败');
  41. $list = [];
  42. $static_url = \Yii::$app->services->setting->platform->get('system.static_url');
  43. foreach ($data['list'] as &$item){
  44. switch ($item['name']){
  45. //门店核销券与门店股东相关联,
  46. case 'Verification':
  47. if(MallAddons::isInstall($this->mall_id,AddonsEnum::ADDONS_NAME_STORE_BOSS_AGENT)){
  48. if(empty($item['cover'])){
  49. $item['cover'] = $static_url.'/static/addons/icon/' . $item['name'] . '.png';
  50. }
  51. $list[] = $item;
  52. }
  53. break;
  54. case AddonsEnum::ADDONS_NAME_HUIFU_PAY:
  55. if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_HUIFU_PAY)&&!empty(HuifuBillShareService::isEnableShare($this->mall_id)) ) {
  56. $list[] = $item;
  57. }
  58. break;
  59. case 'StoreAssociatedUser':
  60. if(empty($item['cover'])){
  61. $item['cover'] = $static_url.'/static/addons/icon/' . $item['name'] . '.png';
  62. }
  63. $list[] = $item;
  64. break;
  65. default:
  66. if(MallAddons::isInstall($this->mall_id,$item['name'])){
  67. if(empty($item['cover'])){
  68. $item['cover'] = $static_url.'/static/addons/icon/' . $item['name'] . '.png';
  69. }
  70. $list[] = $item;
  71. }
  72. }
  73. // if(($item['name'] != AddonsEnum::ADDONS_NAME_HUIFU_PAY && MallAddons::isInstall($this->mall_id,$item['name'])) || $item['name'] == 'StoreAssociatedUser'){
  74. // if(empty($item['cover'])){
  75. // $item['cover'] = $static_url.'/static/addons/icon/' . $item['name'] . '.png';
  76. // }
  77. // $list[] = $item;
  78. // }
  79. }
  80. $data['list'] = $this->getAddonsUrl($list);
  81. return $this->success('获取成功',$data);
  82. } else {
  83. return $this->render($this->action->id);
  84. }
  85. }
  86. /**
  87. * 获取应用默认跳转地址
  88. * @Author:lun
  89. * @Date:2023-12-19 17:20
  90. * @Copyright:copyright(c)2023 广东七件事集团
  91. * @param $addons
  92. * @return mixed
  93. */
  94. public function getAddonsUrl($addons)
  95. {
  96. $addons_indexby = StoreAddons::getAddonsDefaultUrls(array_column($addons, 'name'));
  97. foreach ($addons as &$item) {
  98. $item['url'] = $addons_indexby[$item['name']]['url'];
  99. }
  100. return $addons;
  101. }
  102. }