ShopController.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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'];
  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 = ShopClass::generateGatheringCode($this->sjId, $id);
  108. util::success(['url' => $imgUrl]);
  109. }
  110. //获取小程序的收款码 ssh
  111. public function actionGatheringMiniCode()
  112. {
  113. $id = Yii::$app->request->get('id', 0);
  114. $extend = MerchantExtendService::getBySjId($this->sjId);
  115. if ($extend['miniAuth'] == 0) {
  116. util::fail('您的小程序还没有授权');
  117. }
  118. $shop = ShopService::getById($id);
  119. ShopService::valid($shop, $this->sjId);
  120. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj->attributes, $id);
  121. $file = dirUtil::getImgDir() . $applyMemberCode;
  122. if (file_exists($file) == false) {
  123. util::fail('没有找到注册会员码');
  124. }
  125. $fileName = "门店({$id})小程序收款码.jpg";
  126. $contentType = 'image/jpeg';
  127. header("Cache-control: private");
  128. header("Content-type: $contentType"); //设置要下载的文件类型
  129. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  130. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  131. readfile($file);
  132. }
  133. //下载会员注册码 ssh 2020.2.29
  134. public function actionApplyMemberCode()
  135. {
  136. $id = Yii::$app->request->get('id', 0);
  137. $extend = MerchantExtendService::getBySjId($this->sjId);
  138. if ($extend['miniAuth'] == 0) {
  139. util::fail('您的小程序还没有授权');
  140. }
  141. $shop = ShopService::getById($id);
  142. ShopService::valid($shop, $this->sjId);
  143. $applyMemberCode = wxUtil::generateMemberCode($this->sj->attributes, $id);
  144. $file = dirUtil::getImgDir() . $applyMemberCode;
  145. if (file_exists($file) == false) {
  146. util::fail('没有找到注册会员码');
  147. }
  148. $fileName = "注册会员码{$id}.jpg";
  149. $contentType = 'image/jpeg';
  150. header("Cache-control: private");
  151. header("Content-type: $contentType"); //设置要下载的文件类型
  152. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  153. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  154. readfile($file);
  155. }
  156. //删除门店 ssh 2020.3.1
  157. public function actionDelete()
  158. {
  159. util::fail('禁止操作');
  160. $id = Yii::$app->request->get('id', 0);
  161. util::fail('功能开发中');
  162. $shop = ShopService::getById($id);
  163. ShopService::valid($shop, $this->sjId);
  164. ShopService::deleteShop($shop);
  165. util::complete();
  166. }
  167. //获取门店详情 ssh 2021.4.23
  168. public function actionDetail()
  169. {
  170. $shopId = Yii::$app->request->get('shopId');
  171. if (empty($shopId)) {
  172. $shopId = $this->shopId;
  173. }
  174. $shop = ShopClass::getShopInfo($shopId);
  175. util::success(['info' => $shop]);
  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->attributes;
  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. //获取所有门店linqh 2021.1.31
  198. public function actionAll()
  199. {
  200. $res = [];
  201. $shopAdmin = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  202. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  203. $res = ShopClass::getAllShop($this->sjId);
  204. }
  205. util::success($res);
  206. }
  207. }