ShopController.php 6.6 KB

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