ShopController.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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;
  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. $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. ShopClass::updateShop($id, $data);
  45. util::complete();
  46. }
  47. //添加门店 ssh 2021.1.14
  48. public function actionAdd()
  49. {
  50. $data = Yii::$app->request->post();
  51. $data['merchantId'] = $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;
  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::getByMerchantId($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, $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::getByMerchantId($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, $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. $id = Yii::$app->request->get('id', 0);
  155. $shop = ShopService::getById($id);
  156. ShopClass::valid($shop, $this->sjId);
  157. ShopClass::deleteShop($shop);
  158. util::complete();
  159. }
  160. //获取所有门店linqh 2021.1.31
  161. public function actionAll()
  162. {
  163. $res = [];
  164. $shopAdmin = $this->shopAdmin;
  165. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  166. $res = ShopClass::getAllShop($this->sjId);
  167. }
  168. util::success($res);
  169. }
  170. //切换门店 linqh 2021.1.31
  171. public function actionToggleShop()
  172. {
  173. $shopId = Yii::$app->request->post('shopId', 0);
  174. $res = AdminClass::toggleShop($this->admin, $shopId, $this->sjId, $this->shopAdmin);
  175. util::success($res);
  176. }
  177. //提现信息更新 ssh 2021.3.23
  178. public function actionCashUpdate()
  179. {
  180. $get = Yii::$app->request->get();
  181. $cashAccount = $get['cashAccount'] ?? '';
  182. $cashName = $get['cashName'] ?? '';
  183. if (empty($cashName)) {
  184. util::fail('请填写姓名');
  185. }
  186. if (empty($cashAccount)) {
  187. util::fail('请填写帐号');
  188. }
  189. $shopAdmin = $this->shopAdmin;
  190. $shopId = $shopAdmin['shopId'];
  191. if ($shopAdmin['super'] != 1) {
  192. util::fail('超管才能操作');
  193. }
  194. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName]);
  195. util::complete();
  196. }
  197. //获取门店详情 ssh 2021.4.23
  198. public function actionDetail()
  199. {
  200. $shopId = Yii::$app->request->get('shopId');
  201. if (empty($shopId)) {
  202. $shopId = $this->shopId;
  203. }
  204. $shop = ShopClass::getShopInfo($shopId);
  205. util::success(['info' => $shop]);
  206. }
  207. }