ShopController.php 8.0 KB

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