ShopController.php 6.3 KB

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