ShopController.php 7.0 KB

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