ShopController.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. namespace hd\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\sj\services\MerchantExtendService;
  5. use bizHd\merchant\services\ShopService;
  6. use common\components\dirUtil;
  7. use common\components\util;
  8. use common\components\wxUtil;
  9. use Yii;
  10. class ShopController extends BaseController
  11. {
  12. public $guestAccess = ['all'];
  13. //门店列表 ssh 20202.2.29
  14. public function actionList()
  15. {
  16. $where = [];
  17. $where['merchantId'] = $this->sjId;
  18. $where['delStatus'] = 0;
  19. $list = ShopService::getShopList($where);
  20. util::success($list);
  21. }
  22. //更新门店 ssh 2020.2.29
  23. public function actionUpdate()
  24. {
  25. $data = Yii::$app->request->post();
  26. $data['merchantId'] = $this->sjId;
  27. $id = isset($data['id']) ? $data['id'] : 0;
  28. unset($data['id']);
  29. $shop = ShopService::getById($id);
  30. ShopService::valid($shop, $this->sjId);
  31. ShopService::updateShop($id, $data);
  32. util::complete();
  33. }
  34. public function actionAdd()
  35. {
  36. $data = Yii::$app->request->post();
  37. $data['merchantId'] = $this->sjId;
  38. ShopService::addShop($data);
  39. util::complete();
  40. }
  41. //下载微信和支付宝收款码 ssh 2020.2.29
  42. public function actionGatheringCode()
  43. {
  44. $id = Yii::$app->request->get('id', 0);
  45. $shop = ShopService::getById($id);
  46. ShopService::valid($shop, $this->sjId);
  47. $gatheringCode = ShopService::generateGatheringCode($this->sjId, $id);
  48. $file = dirUtil::getImgDir() . $gatheringCode;
  49. if (file_exists($file) == false) {
  50. util::fail('没有找到收款码');
  51. }
  52. $fileName = "门店({$id})收款码.jpg";
  53. $contentType = 'image/jpeg';
  54. header("Cache-control: private");
  55. header("Content-type: $contentType"); //设置要下载的文件类型
  56. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  57. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  58. readfile($file);
  59. }
  60. //获取小程序的收款码 ssh
  61. public function actionGatheringMiniCode()
  62. {
  63. $id = Yii::$app->request->get('id', 0);
  64. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  65. if ($extend['miniAuth'] == 0) {
  66. util::fail('您的小程序还没有授权');
  67. }
  68. $shop = ShopService::getById($id);
  69. ShopService::valid($shop, $this->sjId);
  70. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj, $id);
  71. $file = dirUtil::getImgDir() . $applyMemberCode;
  72. if (file_exists($file) == false) {
  73. util::fail('没有找到注册会员码');
  74. }
  75. $fileName = "门店({$id})小程序收款码.jpg";
  76. $contentType = 'image/jpeg';
  77. header("Cache-control: private");
  78. header("Content-type: $contentType"); //设置要下载的文件类型
  79. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  80. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  81. readfile($file);
  82. }
  83. //下载会员注册码 ssh 2020.2.29
  84. public function actionApplyMemberCode()
  85. {
  86. $id = Yii::$app->request->get('id', 0);
  87. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  88. if ($extend['miniAuth'] == 0) {
  89. util::fail('您的小程序还没有授权');
  90. }
  91. $shop = ShopService::getById($id);
  92. ShopService::valid($shop, $this->sjId);
  93. $applyMemberCode = wxUtil::generateMemberCode($this->sj, $id);
  94. $file = dirUtil::getImgDir() . $applyMemberCode;
  95. if (file_exists($file) == false) {
  96. util::fail('没有找到注册会员码');
  97. }
  98. $fileName = "注册会员码{$id}.jpg";
  99. $contentType = 'image/jpeg';
  100. header("Cache-control: private");
  101. header("Content-type: $contentType"); //设置要下载的文件类型
  102. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  103. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  104. readfile($file);
  105. }
  106. //删除门店 ssh 2020.3.1
  107. public function actionDelete()
  108. {
  109. $id = Yii::$app->request->get('id', 0);
  110. util::fail('功能开发中');
  111. $shop = ShopService::getById($id);
  112. ShopService::valid($shop, $this->sjId);
  113. ShopService::deleteShop($shop);
  114. util::complete();
  115. }
  116. //获取门店详情 ssh 2021.4.23
  117. public function actionDetail()
  118. {
  119. $shopId = Yii::$app->request->get('shopId');
  120. if (empty($shopId)) {
  121. $shopId = $this->shopId;
  122. }
  123. $shop = ShopClass::getShopInfo($shopId);
  124. util::success(['info' => $shop]);
  125. }
  126. //提现信息更新 ssh 2021.3.23
  127. public function actionCashUpdate()
  128. {
  129. $get = Yii::$app->request->get();
  130. $cashAccount = $get['cashAccount'] ?? '';
  131. $cashName = $get['cashName'] ?? '';
  132. if (empty($cashName)) {
  133. util::fail('请填写姓名');
  134. }
  135. if (empty($cashAccount)) {
  136. util::fail('请填写帐号');
  137. }
  138. $shopAdmin = $this->shopAdmin;
  139. $shopId = $shopAdmin['shopId'];
  140. if ($shopAdmin['super'] != 1) {
  141. util::fail('您没有权限修改');
  142. }
  143. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName]);
  144. util::complete();
  145. }
  146. //获取所有门店linqh 2021.1.31
  147. public function actionAll()
  148. {
  149. $res = [];
  150. $shopAdmin = $this->shopAdmin;
  151. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  152. $res = ShopClass::getAllShop($this->sjId);
  153. }
  154. util::success($res);
  155. }
  156. }