ShopController.php 6.4 KB

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