ShopController.php 5.3 KB

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