ShopController.php 7.5 KB

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