ShopController.php 6.5 KB

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