ShopController.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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;
  19. util::success($shop);
  20. }
  21. //门店列表 ssh 20202.2.29
  22. public function actionList()
  23. {
  24. $where = [];
  25. $where['merchantId'] = $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['merchantId'] = $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. ShopService::updateShop($id, $data);
  40. util::complete();
  41. }
  42. public function actionAdd()
  43. {
  44. $data = Yii::$app->request->post();
  45. $data['merchantId'] = $this->sjId;
  46. $data['shopId'] = $this->shopId;
  47. $data['adminId'] = $this->adminId;
  48. $data['img'] = is_array($data['img']) ? json_encode($data['img']) : $data['img'];
  49. if (isset($data['shopName']) == false || empty($data['shopName'])) {
  50. util::fail('请填写门店名称');
  51. }
  52. $sj = $this->sj;
  53. $sjName = $sj['name'] ?? '';
  54. $data['merchantName'] = $sjName;
  55. $ptStyle = $sj['style'] ?? dict::getDict('ptStyle', 'hd');
  56. $data['ptStyle'] = $ptStyle;
  57. $connection = Yii::$app->db;
  58. $transaction = $connection->beginTransaction();
  59. try {
  60. ShopClass::addShop($data);
  61. $transaction->commit();
  62. util::complete();
  63. } catch (\Exception $exception) {
  64. $transaction->rollBack();
  65. util::fail();
  66. }
  67. }
  68. //切换门店 linqh 2021.1.31
  69. public function actionToggleShop()
  70. {
  71. $shopId = Yii::$app->request->post('shopId', 0);
  72. $res = AdminClass::toggleShop($this->admin, $shopId, $this->sjId, $this->shopAdmin);
  73. util::success($res);
  74. }
  75. //下载微信和支付宝收款码 ssh 2020.2.29
  76. public function actionGatheringCode()
  77. {
  78. $id = Yii::$app->request->get('id', 0);
  79. $shop = ShopService::getById($id);
  80. ShopService::valid($shop, $this->sjId);
  81. $gatheringCode = ShopService::generateGatheringCode($this->sjId, $id);
  82. $file = dirUtil::getImgDir() . $gatheringCode;
  83. if (file_exists($file) == false) {
  84. util::fail('没有找到收款码');
  85. }
  86. $fileName = "门店({$id})收款码.jpg";
  87. $contentType = 'image/jpeg';
  88. header("Cache-control: private");
  89. header("Content-type: $contentType"); //设置要下载的文件类型
  90. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  91. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  92. readfile($file);
  93. }
  94. //获取小程序的收款码 ssh
  95. public function actionGatheringMiniCode()
  96. {
  97. $id = Yii::$app->request->get('id', 0);
  98. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  99. if ($extend['miniAuth'] == 0) {
  100. util::fail('您的小程序还没有授权');
  101. }
  102. $shop = ShopService::getById($id);
  103. ShopService::valid($shop, $this->sjId);
  104. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj, $id);
  105. $file = dirUtil::getImgDir() . $applyMemberCode;
  106. if (file_exists($file) == false) {
  107. util::fail('没有找到注册会员码');
  108. }
  109. $fileName = "门店({$id})小程序收款码.jpg";
  110. $contentType = 'image/jpeg';
  111. header("Cache-control: private");
  112. header("Content-type: $contentType"); //设置要下载的文件类型
  113. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  114. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  115. readfile($file);
  116. }
  117. //下载会员注册码 ssh 2020.2.29
  118. public function actionApplyMemberCode()
  119. {
  120. $id = Yii::$app->request->get('id', 0);
  121. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  122. if ($extend['miniAuth'] == 0) {
  123. util::fail('您的小程序还没有授权');
  124. }
  125. $shop = ShopService::getById($id);
  126. ShopService::valid($shop, $this->sjId);
  127. $applyMemberCode = wxUtil::generateMemberCode($this->sj, $id);
  128. $file = dirUtil::getImgDir() . $applyMemberCode;
  129. if (file_exists($file) == false) {
  130. util::fail('没有找到注册会员码');
  131. }
  132. $fileName = "注册会员码{$id}.jpg";
  133. $contentType = 'image/jpeg';
  134. header("Cache-control: private");
  135. header("Content-type: $contentType"); //设置要下载的文件类型
  136. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  137. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  138. readfile($file);
  139. }
  140. //删除门店 ssh 2020.3.1
  141. public function actionDelete()
  142. {
  143. $id = Yii::$app->request->get('id', 0);
  144. util::fail('功能开发中');
  145. $shop = ShopService::getById($id);
  146. ShopService::valid($shop, $this->sjId);
  147. ShopService::deleteShop($shop);
  148. util::complete();
  149. }
  150. //获取门店详情 ssh 2021.4.23
  151. public function actionDetail()
  152. {
  153. $shopId = Yii::$app->request->get('shopId');
  154. if (empty($shopId)) {
  155. $shopId = $this->shopId;
  156. }
  157. $shop = ShopClass::getShopInfo($shopId);
  158. util::success(['info' => $shop]);
  159. }
  160. //提现信息更新 ssh 2021.3.23
  161. public function actionCashUpdate()
  162. {
  163. $get = Yii::$app->request->get();
  164. $cashAccount = $get['cashAccount'] ?? '';
  165. $cashName = $get['cashName'] ?? '';
  166. if (empty($cashName)) {
  167. util::fail('请填写姓名');
  168. }
  169. if (empty($cashAccount)) {
  170. util::fail('请填写帐号');
  171. }
  172. $shopAdmin = $this->shopAdmin;
  173. $shopId = $shopAdmin['shopId'];
  174. if ($shopAdmin['super'] != 1) {
  175. util::fail('超管才能操作');
  176. }
  177. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName]);
  178. util::complete();
  179. }
  180. //获取所有门店linqh 2021.1.31
  181. public function actionAll()
  182. {
  183. $res = [];
  184. $shopAdmin = $this->shopAdmin;
  185. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  186. $res = ShopClass::getAllShop($this->sjId);
  187. }
  188. util::success($res);
  189. }
  190. }