ShopController.php 8.2 KB

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