ShopController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\merchant\services\MerchantExtendService;
  4. use bizGhs\merchant\classes\ShopClass;
  5. use bizGhs\merchant\services\ShopService;
  6. use common\components\dirUtil;
  7. use common\components\httpUtil;
  8. use common\components\util;
  9. use common\components\wxUtil;
  10. use Yii;
  11. class ShopController extends BaseController
  12. {
  13. //门店列表 shish 2021.1.14
  14. public function actionList()
  15. {
  16. $where = [];
  17. $where['ghsId'] = $this->ghsId;
  18. $where['delStatus'] = 0;
  19. $list = ShopClass::getShopList($where);
  20. util::success($list);
  21. }
  22. //更新门店 shish 2020.2.29
  23. public function actionUpdate()
  24. {
  25. $data = Yii::$app->request->post();
  26. $data['ghsId'] = $this->ghsId;
  27. $id = $data['id'] ?? 0;
  28. $shop = ShopService::getById($id);
  29. if (empty($shop)) {
  30. util::fail('没有找到门店');
  31. }
  32. ShopClass::valid($shop, $this->ghsId);
  33. ShopClass::updateShop($id, $data);
  34. util::complete();
  35. }
  36. //添加门店 shish 2021.1.14
  37. public function actionAdd()
  38. {
  39. $data = Yii::$app->request->post();
  40. $data['ghsId'] = $this->ghsId;
  41. ShopClass::addShop($data);
  42. util::complete();
  43. }
  44. //PC下载微信和支付宝收款码 shish 2020.2.29
  45. public function actionGatheringCode()
  46. {
  47. $id = Yii::$app->request->get('id', 0);
  48. $shop = ShopService::getById($id);
  49. ShopClass::valid($shop, $this->ghsId);
  50. $gatheringCode = ShopClass::generateGatheringCode($this->ghsId, $id);
  51. $file = dirUtil::getImgDir() . $gatheringCode;
  52. if (file_exists($file) == false) {
  53. util::fail('没有找到收款码');
  54. }
  55. if (httpUtil::isMiniProgram()) {
  56. $imgUrl = Yii::$app->params['imgHost'] . $gatheringCode;
  57. util::success(['imgUrl' => $imgUrl]);
  58. }
  59. $fileName = "门店({$id})收款码.jpg";
  60. $contentType = 'image/jpeg';
  61. header("Cache-control: private");
  62. header("Content-type: $contentType"); //设置要下载的文件类型
  63. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  64. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  65. readfile($file);
  66. }
  67. //PC获取小程序的收款码 shish
  68. public function actionGatheringMiniCode()
  69. {
  70. $id = Yii::$app->request->get('id', 0);
  71. $extend = MerchantExtendService::getByghsId($this->ghsId);
  72. if ($extend['miniAuth'] == 0) {
  73. util::fail('您的小程序还没有授权');
  74. }
  75. $shop = ShopService::getById($id);
  76. ShopClass::valid($shop, $this->ghsId);
  77. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->merchant, $id);
  78. $file = dirUtil::getImgDir() . $applyMemberCode;
  79. if (file_exists($file) == false) {
  80. util::fail('没有找到注册会员码');
  81. }
  82. if (httpUtil::isMiniProgram()) {
  83. $imgUrl = Yii::$app->params['imgHost'] . $applyMemberCode;
  84. util::success(['imgUrl' => $imgUrl]);
  85. }
  86. $fileName = "门店({$id})小程序收款码.jpg";
  87. $contentType = 'image/jpeg';
  88. header("Cache-control: private");
  89. header("Content-type: $contentType"); //设置要下载的文件类型
  90. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  91. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  92. readfile($file);
  93. }
  94. //PC下载会员注册码 shish 2020.2.29
  95. public function actionApplyMemberCode()
  96. {
  97. $id = Yii::$app->request->get('id', 0);
  98. $extend = MerchantExtendService::getByghsId($this->ghsId);
  99. if ($extend['miniAuth'] == 0) {
  100. util::fail('您的小程序还没有授权');
  101. }
  102. $shop = ShopService::getById($id);
  103. ShopClass::valid($shop, $this->ghsId);
  104. $applyMemberCode = wxUtil::generateMemberCode($this->merchant, $id);
  105. $file = dirUtil::getImgDir() . $applyMemberCode;
  106. if (file_exists($file) == false) {
  107. util::fail('没有找到注册会员码');
  108. }
  109. if (httpUtil::isMiniProgram()) {
  110. $imgUrl = Yii::$app->params['imgHost'] . $applyMemberCode;
  111. util::success(['imgUrl' => $imgUrl]);
  112. }
  113. $fileName = "注册会员码{$id}.jpg";
  114. $contentType = 'image/jpeg';
  115. header("Cache-control: private");
  116. header("Content-type: $contentType"); //设置要下载的文件类型
  117. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  118. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  119. readfile($file);
  120. }
  121. //删除门店 shish 2020.3.1
  122. public function actionDelete()
  123. {
  124. $id = Yii::$app->request->get('id', 0);
  125. $shop = ShopService::getById($id);
  126. ShopClass::valid($shop, $this->ghsId);
  127. ShopClass::deleteShop($shop);
  128. util::complete();
  129. }
  130. }