ShopController.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. ShopService::updateShop($id, $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);
  81. ShopService::valid($shop, $this->sjId);
  82. $gatheringCode = ShopService::generateGatheringCode($this->sjId, $id);
  83. $file = dirUtil::getImgDir() . $gatheringCode;
  84. if (file_exists($file) == false) {
  85. util::fail('没有找到收款码');
  86. }
  87. $fileName = "门店({$id})收款码.jpg";
  88. $contentType = 'image/jpeg';
  89. header("Cache-control: private");
  90. header("Content-type: $contentType"); //设置要下载的文件类型
  91. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  92. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  93. readfile($file);
  94. }
  95. //获取小程序的收款码 ssh
  96. public function actionGatheringMiniCode()
  97. {
  98. $id = Yii::$app->request->get('id', 0);
  99. $extend = MerchantExtendService::getBySjId($this->sjId);
  100. if ($extend['miniAuth'] == 0) {
  101. util::fail('您的小程序还没有授权');
  102. }
  103. $shop = ShopService::getById($id);
  104. ShopService::valid($shop, $this->sjId);
  105. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj->attributes, $id);
  106. $file = dirUtil::getImgDir() . $applyMemberCode;
  107. if (file_exists($file) == false) {
  108. util::fail('没有找到注册会员码');
  109. }
  110. $fileName = "门店({$id})小程序收款码.jpg";
  111. $contentType = 'image/jpeg';
  112. header("Cache-control: private");
  113. header("Content-type: $contentType"); //设置要下载的文件类型
  114. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  115. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  116. readfile($file);
  117. }
  118. //下载会员注册码 ssh 2020.2.29
  119. public function actionApplyMemberCode()
  120. {
  121. $id = Yii::$app->request->get('id', 0);
  122. $extend = MerchantExtendService::getBySjId($this->sjId);
  123. if ($extend['miniAuth'] == 0) {
  124. util::fail('您的小程序还没有授权');
  125. }
  126. $shop = ShopService::getById($id);
  127. ShopService::valid($shop, $this->sjId);
  128. $applyMemberCode = wxUtil::generateMemberCode($this->sj->attributes, $id);
  129. $file = dirUtil::getImgDir() . $applyMemberCode;
  130. if (file_exists($file) == false) {
  131. util::fail('没有找到注册会员码');
  132. }
  133. $fileName = "注册会员码{$id}.jpg";
  134. $contentType = 'image/jpeg';
  135. header("Cache-control: private");
  136. header("Content-type: $contentType"); //设置要下载的文件类型
  137. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  138. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  139. readfile($file);
  140. }
  141. //删除门店 ssh 2020.3.1
  142. public function actionDelete()
  143. {
  144. util::fail('禁止操作');
  145. $id = Yii::$app->request->get('id', 0);
  146. util::fail('功能开发中');
  147. $shop = ShopService::getById($id);
  148. ShopService::valid($shop, $this->sjId);
  149. ShopService::deleteShop($shop);
  150. util::complete();
  151. }
  152. //获取门店详情 ssh 2021.4.23
  153. public function actionDetail()
  154. {
  155. $shopId = Yii::$app->request->get('shopId');
  156. if (empty($shopId)) {
  157. $shopId = $this->shopId;
  158. }
  159. $shop = ShopClass::getShopInfo($shopId);
  160. util::success(['info' => $shop]);
  161. }
  162. //提现信息更新 ssh 2021.3.23
  163. public function actionCashUpdate()
  164. {
  165. $get = Yii::$app->request->get();
  166. $cashAccount = $get['cashAccount'] ?? '';
  167. $cashName = $get['cashName'] ?? '';
  168. if (empty($cashName)) {
  169. util::fail('请填写姓名');
  170. }
  171. if (empty($cashAccount)) {
  172. util::fail('请填写帐号');
  173. }
  174. $shopAdmin = $this->shopAdmin->attributes;
  175. $shopId = $shopAdmin['shopId'];
  176. if ($shopAdmin['super'] != 1) {
  177. util::fail('超管才能操作');
  178. }
  179. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName]);
  180. util::complete();
  181. }
  182. //获取所有门店linqh 2021.1.31
  183. public function actionAll()
  184. {
  185. $res = [];
  186. $shopAdmin = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  187. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  188. $res = ShopClass::getAllShop($this->sjId);
  189. }
  190. util::success($res);
  191. }
  192. }