ShopController.php 8.0 KB

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