ShopController.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopAdminClass;
  4. use biz\sj\services\MerchantExtendService;
  5. use bizGhs\admin\classes\AdminClass;
  6. use bizGhs\merchant\classes\ShopClass;
  7. use bizGhs\merchant\services\ShopService;
  8. use common\components\dict;
  9. use common\components\dirUtil;
  10. use common\components\httpUtil;
  11. use common\components\imgUtil;
  12. use common\components\util;
  13. use common\components\wxUtil;
  14. use Yii;
  15. class ShopController extends BaseController
  16. {
  17. public $guestAccess = ['all'];
  18. //获取当前门店信息 ssh 2021.3.27
  19. public function actionCurrentShop()
  20. {
  21. $shop = $this->shop->attributes;
  22. util::success($shop);
  23. }
  24. //门店列表 ssh 2021.1.14
  25. public function actionList()
  26. {
  27. $where = [];
  28. $where['sjId'] = $this->sjId;
  29. $where['delStatus'] = 0;
  30. $list = ShopClass::getShopList($where);
  31. util::success($list);
  32. }
  33. //更新门店 ssh 2020.2.29
  34. public function actionUpdate()
  35. {
  36. $data = Yii::$app->request->post();
  37. $data['sjId'] = $this->sjId;
  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. \biz\shop\classes\ShopClass::updateShop($shop, $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 = ShopClass::getAllShop($this->sjId);
  166. util::success($res);
  167. }
  168. //切换门店 linqh 2021.1.31
  169. public function actionToggleShop()
  170. {
  171. $shopId = Yii::$app->request->post('shopId', 0);
  172. $res = AdminClass::toggleShop($this->admin->attributes, $shopId, $this->sjId, $this->shopAdmin->attributes);
  173. util::success($res);
  174. }
  175. //提现信息更新 ssh 2021.3.23
  176. public function actionCashUpdate()
  177. {
  178. $get = Yii::$app->request->get();
  179. $cashAccount = $get['cashAccount'] ?? '';
  180. $cashName = $get['cashName'] ?? '';
  181. $cashBank = $get['cashBank'] ?? '';
  182. if (empty($cashName)) {
  183. util::fail('请填写姓名');
  184. }
  185. if (empty($cashAccount)) {
  186. util::fail('请填写银行卡号');
  187. }
  188. if (empty($cashBank)) {
  189. util::fail('请输入开户行');
  190. }
  191. $shopAdmin = $this->shopAdmin;
  192. $shopId = $shopAdmin->shopId ?? 0;
  193. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  194. util::fail('超管才能操作');
  195. }
  196. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName, 'cashBank' => $cashBank]);
  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. //获取平台所有的供应商门店 shish 20210908
  210. public function actionGetPtGhsShop()
  211. {
  212. $shop = ShopClass::getAllByCondition(['ptStyle' => 2], 'id asc', '*');
  213. util::success(['list' => $shop]);
  214. }
  215. //切换门店 shish 20210908
  216. public function actionSwitchGhsShop()
  217. {
  218. $shopAdmin = $this->shopAdmin;
  219. $adminId = $shopAdmin->adminId ?? 0;
  220. if ($adminId != 2) {
  221. util::fail('没有权限');
  222. }
  223. $shopId = Yii::$app->request->get('shopId', 0);
  224. $admin = \biz\admin\classes\AdminClass::getById($adminId, true);
  225. if (empty($admin)) {
  226. util::fail('没有找到这个管理员');
  227. }
  228. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $shopId, 'adminId' => $adminId], true);
  229. if (empty($shopAdmin)) {
  230. util::fail('您不是这个店里的员工');
  231. }
  232. $admin->currentShopId = $shopId;
  233. $admin->save();
  234. util::complete();
  235. }
  236. }