ShopController.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 20202.2.29
  15. public function actionList()
  16. {
  17. $where = [];
  18. $where['merchantId'] = $this->sjId;
  19. $where['delStatus'] = 0;
  20. $list = ShopService::getShopList($where);
  21. util::success($list);
  22. }
  23. //更新门店 ssh 2020.2.29
  24. public function actionUpdate()
  25. {
  26. $data = Yii::$app->request->post();
  27. $data['merchantId'] = $this->sjId;
  28. $id = isset($data['id']) ? $data['id'] : 0;
  29. unset($data['id']);
  30. $shop = ShopService::getById($id);
  31. ShopService::valid($shop, $this->sjId);
  32. ShopService::updateShop($id, $data);
  33. util::complete();
  34. }
  35. public function actionAdd()
  36. {
  37. $data = Yii::$app->request->post();
  38. $data['merchantId'] = $this->sjId;
  39. ShopService::addShop($data);
  40. util::complete();
  41. }
  42. //切换门店 linqh 2021.1.31
  43. public function actionToggleShop()
  44. {
  45. $shopId = Yii::$app->request->post('shopId', 0);
  46. $res = AdminClass::toggleShop($this->admin, $shopId, $this->sjId, $this->shopAdmin);
  47. util::success($res);
  48. }
  49. //下载微信和支付宝收款码 ssh 2020.2.29
  50. public function actionGatheringCode()
  51. {
  52. $id = Yii::$app->request->get('id', 0);
  53. $shop = ShopService::getById($id);
  54. ShopService::valid($shop, $this->sjId);
  55. $gatheringCode = ShopService::generateGatheringCode($this->sjId, $id);
  56. $file = dirUtil::getImgDir() . $gatheringCode;
  57. if (file_exists($file) == false) {
  58. util::fail('没有找到收款码');
  59. }
  60. $fileName = "门店({$id})收款码.jpg";
  61. $contentType = 'image/jpeg';
  62. header("Cache-control: private");
  63. header("Content-type: $contentType"); //设置要下载的文件类型
  64. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  65. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  66. readfile($file);
  67. }
  68. //获取小程序的收款码 ssh
  69. public function actionGatheringMiniCode()
  70. {
  71. $id = Yii::$app->request->get('id', 0);
  72. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  73. if ($extend['miniAuth'] == 0) {
  74. util::fail('您的小程序还没有授权');
  75. }
  76. $shop = ShopService::getById($id);
  77. ShopService::valid($shop, $this->sjId);
  78. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj, $id);
  79. $file = dirUtil::getImgDir() . $applyMemberCode;
  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 2020.2.29
  92. public function actionApplyMemberCode()
  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::generateMemberCode($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.3.1
  115. public function actionDelete()
  116. {
  117. $id = Yii::$app->request->get('id', 0);
  118. util::fail('功能开发中');
  119. $shop = ShopService::getById($id);
  120. ShopService::valid($shop, $this->sjId);
  121. ShopService::deleteShop($shop);
  122. util::complete();
  123. }
  124. //获取门店详情 ssh 2021.4.23
  125. public function actionDetail()
  126. {
  127. $shopId = Yii::$app->request->get('shopId');
  128. if (empty($shopId)) {
  129. $shopId = $this->shopId;
  130. }
  131. $shop = ShopClass::getShopInfo($shopId);
  132. util::success(['info' => $shop]);
  133. }
  134. //提现信息更新 ssh 2021.3.23
  135. public function actionCashUpdate()
  136. {
  137. $get = Yii::$app->request->get();
  138. $cashAccount = $get['cashAccount'] ?? '';
  139. $cashName = $get['cashName'] ?? '';
  140. if (empty($cashName)) {
  141. util::fail('请填写姓名');
  142. }
  143. if (empty($cashAccount)) {
  144. util::fail('请填写帐号');
  145. }
  146. $shopAdmin = $this->shopAdmin;
  147. $shopId = $shopAdmin['shopId'];
  148. if ($shopAdmin['super'] != 1) {
  149. util::fail('您没有权限修改');
  150. }
  151. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName]);
  152. util::complete();
  153. }
  154. //获取所有门店linqh 2021.1.31
  155. public function actionAll()
  156. {
  157. $res = [];
  158. $shopAdmin = $this->shopAdmin;
  159. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  160. $res = ShopClass::getAllShop($this->sjId);
  161. }
  162. util::success($res);
  163. }
  164. }