ShopController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\sj\services\MerchantExtendService;
  4. use bizGhs\admin\classes\AdminClass;
  5. use bizGhs\merchant\classes\ShopClass;
  6. use bizGhs\merchant\services\ShopService;
  7. use common\components\dirUtil;
  8. use common\components\httpUtil;
  9. use common\components\imgUtil;
  10. use common\components\util;
  11. use common\components\wxUtil;
  12. use Yii;
  13. use yii\web\UrlManager;
  14. class ShopController extends BaseController
  15. {
  16. //门店列表 shish 2021.1.14
  17. public function actionList()
  18. {
  19. $where = [];
  20. $where['merchantId'] = $this->sjId;
  21. $where['delStatus'] = 0;
  22. $list = ShopClass::getShopList($where);
  23. util::success($list);
  24. }
  25. //更新门店 shish 2020.2.29
  26. public function actionUpdate()
  27. {
  28. $data = Yii::$app->request->post();
  29. $data['merchantId'] = $this->sjId;
  30. $id = $data['id'] ?? 0;
  31. $shop = ShopService::getById($id);
  32. if (empty($shop)) {
  33. util::fail('没有找到门店');
  34. }
  35. ShopClass::valid($shop, $this->sjId);
  36. ShopClass::updateShop($id, $data);
  37. util::complete();
  38. }
  39. //添加门店 shish 2021.1.14
  40. public function actionAdd()
  41. {
  42. $data = Yii::$app->request->post();
  43. $data['merchantId'] = $this->sjId;
  44. ShopClass::addShop($data);
  45. util::complete();
  46. }
  47. //PC下载微信和支付宝收款码 shish 2020.2.29
  48. public function actionGatheringCode()
  49. {
  50. $id = Yii::$app->request->get('id', 0);
  51. $shop = ShopService::getById($id);
  52. ShopClass::valid($shop, $this->sjId);
  53. $gatheringCode = ShopClass::generateGatheringCode($this->sjId, $id);
  54. $file = dirUtil::getImgDir() . $gatheringCode;
  55. if (file_exists($file) == false) {
  56. util::fail('没有找到收款码');
  57. }
  58. if (httpUtil::isMiniProgram()) {
  59. $imgUrl = imgUtil::getPrefix() . $gatheringCode;
  60. util::success(['imgUrl' => $imgUrl]);
  61. }
  62. $fileName = "门店({$id})收款码.jpg";
  63. $contentType = 'image/jpeg';
  64. header("Cache-control: private");
  65. header("Content-type: $contentType"); //设置要下载的文件类型
  66. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  67. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  68. readfile($file);
  69. }
  70. //PC获取小程序的收款码 shish
  71. public function actionGatheringMiniCode()
  72. {
  73. $id = Yii::$app->request->get('id', 0);
  74. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  75. if ($extend['miniAuth'] == 0) {
  76. util::fail('您的小程序还没有授权');
  77. }
  78. $shop = ShopService::getById($id);
  79. ShopClass::valid($shop, $this->sjId);
  80. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj, $id);
  81. $file = dirUtil::getImgDir() . $applyMemberCode;
  82. if (file_exists($file) == false) {
  83. util::fail('没有找到注册会员码');
  84. }
  85. if (httpUtil::isMiniProgram()) {
  86. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  87. util::success(['imgUrl' => $imgUrl]);
  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. //PC下载会员注册码 shish 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. ShopClass::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. if (httpUtil::isMiniProgram()) {
  113. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  114. util::success(['imgUrl' => $imgUrl]);
  115. }
  116. $fileName = "注册会员码{$id}.jpg";
  117. $contentType = 'image/jpeg';
  118. header("Cache-control: private");
  119. header("Content-type: $contentType"); //设置要下载的文件类型
  120. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  121. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  122. readfile($file);
  123. }
  124. //删除门店 shish 2020.3.1
  125. public function actionDelete()
  126. {
  127. $id = Yii::$app->request->get('id', 0);
  128. $shop = ShopService::getById($id);
  129. ShopClass::valid($shop, $this->sjId);
  130. ShopClass::deleteShop($shop);
  131. util::complete();
  132. }
  133. //获取所有门店linqh 2021.1.31
  134. public function actionAll()
  135. {
  136. $res = [];
  137. $shopAdmin = $this->shopAdmin;
  138. if ($shopAdmin['super'] == 1) {
  139. $res = ShopClass::getAllShop($this->sjId);
  140. }
  141. util::success($res);
  142. }
  143. //切换门店 linqh 2021.1.31
  144. public function actionToggleShop()
  145. {
  146. $shopId = Yii::$app->request->post('shopId', 0);
  147. $res = AdminClass::toggleShop($this->admin, $shopId, $this->sjId, $this->shopAdmin);
  148. util::success($res);
  149. }
  150. //提现信息更新 shish 2021.3.23
  151. public function actionCashUpdate()
  152. {
  153. $get = Yii::$app->request->get();
  154. $cashAccount = $get['cashAccount'] ?? '';
  155. $cashName = $get['cashName'] ?? '';
  156. if (empty($cashName)) {
  157. util::fail('请填写姓名');
  158. }
  159. if (empty($cashAccount)) {
  160. util::fail('请填写帐号');
  161. }
  162. $shopAdmin = $this->shopAdmin;
  163. $shopId = $shopAdmin['shopId'];
  164. if ($shopAdmin['super'] != 1) {
  165. util::fail('您没有权限修改');
  166. }
  167. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName]);
  168. util::complete();
  169. }
  170. }