ShopController.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. class ShopController extends BaseController
  14. {
  15. public $guestAccess = ['all'];
  16. //获取当前门店信息 ssh 2021.3.27
  17. public function actionCurrentShop()
  18. {
  19. $shop = $this->shop;
  20. util::success($shop);
  21. }
  22. //门店列表 ssh 2021.1.14
  23. public function actionList()
  24. {
  25. $where = [];
  26. $where['merchantId'] = $this->sjId;
  27. $where['delStatus'] = 0;
  28. $list = ShopClass::getShopList($where);
  29. util::success($list);
  30. }
  31. //更新门店 ssh 2020.2.29
  32. public function actionUpdate()
  33. {
  34. $data = Yii::$app->request->post();
  35. $data['merchantId'] = $this->sjId;
  36. $data['img'] = is_array($data['img']) ? json_encode($data['img']) : $data['img'];
  37. $id = $data['id'] ?? 0;
  38. $shop = ShopService::getById($id);
  39. if (empty($shop)) {
  40. util::fail('没有找到门店');
  41. }
  42. ShopClass::valid($shop, $this->sjId);
  43. ShopClass::updateShop($id, $data);
  44. util::complete();
  45. }
  46. //添加门店 ssh 2021.1.14
  47. public function actionAdd()
  48. {
  49. $data = Yii::$app->request->post();
  50. $data['merchantId'] = $this->sjId;
  51. $data['shopId'] = $this->shopId;
  52. $data['adminId'] = $this->adminId;
  53. $data['img'] = is_array($data['img']) ? json_encode($data['img']) : $data['img'];
  54. if (isset($data['shopName']) == false || empty($data['shopName'])) {
  55. util::fail('请填写门店名称');
  56. }
  57. $sj = $this->sj;
  58. $sjName = $sj['name'] ?? '';
  59. $data['merchantName'] = $sjName;
  60. $connection = Yii::$app->db;
  61. $transaction = $connection->beginTransaction();
  62. try {
  63. \biz\shop\classes\ShopClass::addShop($data);
  64. $transaction->commit();
  65. util::complete();
  66. } catch (\Exception $exception) {
  67. $transaction->rollBack();
  68. util::fail();
  69. }
  70. }
  71. //PC下载微信和支付宝收款码 ssh 2020.2.29
  72. public function actionGatheringCode()
  73. {
  74. $id = Yii::$app->request->get('id', 0);
  75. $shop = ShopService::getById($id);
  76. ShopClass::valid($shop, $this->sjId);
  77. $gatheringCode = ShopClass::generateGatheringCode($this->sjId, $id);
  78. $file = dirUtil::getImgDir() . $gatheringCode;
  79. if (file_exists($file) == false) {
  80. util::fail('没有找到收款码');
  81. }
  82. if (httpUtil::isMiniProgram()) {
  83. $imgUrl = imgUtil::getPrefix() . $gatheringCode;
  84. util::success(['imgUrl' => $imgUrl]);
  85. }
  86. $fileName = "门店({$id})收款码.jpg";
  87. $contentType = 'image/jpeg';
  88. header("Cache-control: private");
  89. header("Content-type: $contentType"); //设置要下载的文件类型
  90. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  91. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  92. readfile($file);
  93. }
  94. //PC获取小程序的收款码 ssh
  95. public function actionGatheringMiniCode()
  96. {
  97. $id = Yii::$app->request->get('id', 0);
  98. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  99. if ($extend['miniAuth'] == 0) {
  100. util::fail('您的小程序还没有授权');
  101. }
  102. $shop = ShopService::getById($id);
  103. ShopClass::valid($shop, $this->sjId);
  104. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj, $id);
  105. $file = dirUtil::getImgDir() . $applyMemberCode;
  106. if (file_exists($file) == false) {
  107. util::fail('没有找到注册会员码');
  108. }
  109. if (httpUtil::isMiniProgram()) {
  110. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  111. util::success(['imgUrl' => $imgUrl]);
  112. }
  113. $fileName = "门店({$id})小程序收款码.jpg";
  114. $contentType = 'image/jpeg';
  115. header("Cache-control: private");
  116. header("Content-type: $contentType"); //设置要下载的文件类型
  117. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  118. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  119. readfile($file);
  120. }
  121. //PC下载会员注册码 ssh 2020.2.29
  122. public function actionApplyMemberCode()
  123. {
  124. $id = Yii::$app->request->get('id', 0);
  125. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  126. if ($extend['miniAuth'] == 0) {
  127. util::fail('您的小程序还没有授权');
  128. }
  129. $shop = ShopService::getById($id);
  130. ShopClass::valid($shop, $this->sjId);
  131. $applyMemberCode = wxUtil::generateMemberCode($this->sj, $id);
  132. $file = dirUtil::getImgDir() . $applyMemberCode;
  133. if (file_exists($file) == false) {
  134. util::fail('没有找到注册会员码');
  135. }
  136. if (httpUtil::isMiniProgram()) {
  137. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  138. util::success(['imgUrl' => $imgUrl]);
  139. }
  140. $fileName = "注册会员码{$id}.jpg";
  141. $contentType = 'image/jpeg';
  142. header("Cache-control: private");
  143. header("Content-type: $contentType"); //设置要下载的文件类型
  144. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  145. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  146. readfile($file);
  147. }
  148. //删除门店 ssh 2020.3.1
  149. public function actionDelete()
  150. {
  151. $id = Yii::$app->request->get('id', 0);
  152. $shop = ShopService::getById($id);
  153. ShopClass::valid($shop, $this->sjId);
  154. ShopClass::deleteShop($shop);
  155. util::complete();
  156. }
  157. //获取所有门店linqh 2021.1.31
  158. public function actionAll()
  159. {
  160. $res = [];
  161. $shopAdmin = $this->shopAdmin;
  162. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  163. $res = ShopClass::getAllShop($this->sjId);
  164. }
  165. util::success($res);
  166. }
  167. //切换门店 linqh 2021.1.31
  168. public function actionToggleShop()
  169. {
  170. $shopId = Yii::$app->request->post('shopId', 0);
  171. $res = AdminClass::toggleShop($this->admin, $shopId, $this->sjId, $this->shopAdmin);
  172. util::success($res);
  173. }
  174. //提现信息更新 ssh 2021.3.23
  175. public function actionCashUpdate()
  176. {
  177. $get = Yii::$app->request->get();
  178. $cashAccount = $get['cashAccount'] ?? '';
  179. $cashName = $get['cashName'] ?? '';
  180. if (empty($cashName)) {
  181. util::fail('请填写姓名');
  182. }
  183. if (empty($cashAccount)) {
  184. util::fail('请填写帐号');
  185. }
  186. $shopAdmin = $this->shopAdmin;
  187. $shopId = $shopAdmin['shopId'];
  188. if ($shopAdmin['super'] != 1) {
  189. util::fail('超管才能操作');
  190. }
  191. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName]);
  192. util::complete();
  193. }
  194. //获取门店详情 ssh 2021.4.23
  195. public function actionDetail()
  196. {
  197. $shopId = Yii::$app->request->get('shopId');
  198. if (empty($shopId)) {
  199. $shopId = $this->shopId;
  200. }
  201. $shop = ShopClass::getShopInfo($shopId);
  202. util::success(['info' => $shop]);
  203. }
  204. }