ShopController.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. class ShopController extends BaseController
  14. {
  15. public $guestAccess = ['all'];
  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. $data['img'] = is_array($data['img']) ? json_encode($data['img']) : $data['img'];
  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. $data['shopId'] = $this->shopId;
  52. $data['adminId'] = $this->adminId;
  53. $data['img'] = is_array($data['img']) ? json_encode($data['img']) : $data['img'];
  54. $connection = Yii::$app->db;
  55. $transaction = $connection->beginTransaction();
  56. try {
  57. $shop = \biz\shop\classes\ShopClass::addShop($data);
  58. $transaction->commit();
  59. util::complete();
  60. } catch (\Exception $exception) {
  61. $transaction->rollBack();
  62. util::fail();
  63. }
  64. }
  65. //PC下载微信和支付宝收款码 ssh 2020.2.29
  66. public function actionGatheringCode()
  67. {
  68. $id = Yii::$app->request->get('id', 0);
  69. $shop = ShopService::getById($id);
  70. ShopClass::valid($shop, $this->sjId);
  71. $gatheringCode = ShopClass::generateGatheringCode($this->sjId, $id);
  72. $file = dirUtil::getImgDir() . $gatheringCode;
  73. if (file_exists($file) == false) {
  74. util::fail('没有找到收款码');
  75. }
  76. if (httpUtil::isMiniProgram()) {
  77. $imgUrl = imgUtil::getPrefix() . $gatheringCode;
  78. util::success(['imgUrl' => $imgUrl]);
  79. }
  80. $fileName = "门店({$id})收款码.jpg";
  81. $contentType = 'image/jpeg';
  82. header("Cache-control: private");
  83. header("Content-type: $contentType"); //设置要下载的文件类型
  84. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  85. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  86. readfile($file);
  87. }
  88. //PC获取小程序的收款码 ssh
  89. public function actionGatheringMiniCode()
  90. {
  91. $id = Yii::$app->request->get('id', 0);
  92. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  93. if ($extend['miniAuth'] == 0) {
  94. util::fail('您的小程序还没有授权');
  95. }
  96. $shop = ShopService::getById($id);
  97. ShopClass::valid($shop, $this->sjId);
  98. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj, $id);
  99. $file = dirUtil::getImgDir() . $applyMemberCode;
  100. if (file_exists($file) == false) {
  101. util::fail('没有找到注册会员码');
  102. }
  103. if (httpUtil::isMiniProgram()) {
  104. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  105. util::success(['imgUrl' => $imgUrl]);
  106. }
  107. $fileName = "门店({$id})小程序收款码.jpg";
  108. $contentType = 'image/jpeg';
  109. header("Cache-control: private");
  110. header("Content-type: $contentType"); //设置要下载的文件类型
  111. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  112. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  113. readfile($file);
  114. }
  115. //PC下载会员注册码 ssh 2020.2.29
  116. public function actionApplyMemberCode()
  117. {
  118. $id = Yii::$app->request->get('id', 0);
  119. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  120. if ($extend['miniAuth'] == 0) {
  121. util::fail('您的小程序还没有授权');
  122. }
  123. $shop = ShopService::getById($id);
  124. ShopClass::valid($shop, $this->sjId);
  125. $applyMemberCode = wxUtil::generateMemberCode($this->sj, $id);
  126. $file = dirUtil::getImgDir() . $applyMemberCode;
  127. if (file_exists($file) == false) {
  128. util::fail('没有找到注册会员码');
  129. }
  130. if (httpUtil::isMiniProgram()) {
  131. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  132. util::success(['imgUrl' => $imgUrl]);
  133. }
  134. $fileName = "注册会员码{$id}.jpg";
  135. $contentType = 'image/jpeg';
  136. header("Cache-control: private");
  137. header("Content-type: $contentType"); //设置要下载的文件类型
  138. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  139. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  140. readfile($file);
  141. }
  142. //删除门店 ssh 2020.3.1
  143. public function actionDelete()
  144. {
  145. $id = Yii::$app->request->get('id', 0);
  146. $shop = ShopService::getById($id);
  147. ShopClass::valid($shop, $this->sjId);
  148. ShopClass::deleteShop($shop);
  149. util::complete();
  150. }
  151. //获取所有门店linqh 2021.1.31
  152. public function actionAll()
  153. {
  154. $res = [];
  155. $shopAdmin = $this->shopAdmin;
  156. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  157. $res = ShopClass::getAllShop($this->sjId);
  158. }
  159. util::success($res);
  160. }
  161. //切换门店 linqh 2021.1.31
  162. public function actionToggleShop()
  163. {
  164. $shopId = Yii::$app->request->post('shopId', 0);
  165. $res = AdminClass::toggleShop($this->admin, $shopId, $this->sjId, $this->shopAdmin);
  166. util::success($res);
  167. }
  168. //提现信息更新 ssh 2021.3.23
  169. public function actionCashUpdate()
  170. {
  171. $get = Yii::$app->request->get();
  172. $cashAccount = $get['cashAccount'] ?? '';
  173. $cashName = $get['cashName'] ?? '';
  174. if (empty($cashName)) {
  175. util::fail('请填写姓名');
  176. }
  177. if (empty($cashAccount)) {
  178. util::fail('请填写帐号');
  179. }
  180. $shopAdmin = $this->shopAdmin;
  181. $shopId = $shopAdmin['shopId'];
  182. if ($shopAdmin['super'] != 1) {
  183. util::fail('超管才能操作');
  184. }
  185. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName]);
  186. util::complete();
  187. }
  188. //获取门店详情 ssh 2021.4.23
  189. public function actionDetail()
  190. {
  191. $shopId = Yii::$app->request->get('shopId');
  192. if (empty($shopId)) {
  193. $shopId = $this->shopId;
  194. }
  195. $shop = ShopClass::getShopInfo($shopId);
  196. util::success(['info' => $shop]);
  197. }
  198. }