ShopController.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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['img'] = is_array($data['img']) ? json_encode($data['img']) : $data['img'];
  55. $connection = Yii::$app->db;
  56. $transaction = $connection->beginTransaction();
  57. try {
  58. $shop = ShopClass::addShop($data);
  59. $shopId = $shop['id'];
  60. //门店product 同步数据 linqh 2021.4.18
  61. $product = ProductClass::getAllProduct($this->sjId, $this->shopId, "name,cover,classId,itemId,rank,price,priceLabel,cost,addPrice,stockWarning,weight,alias,py,ratio,bigUnit,smallUnit,bigUnitId,smallUnitId,inTurn");
  62. $productData = [];
  63. foreach ($product as $v) {
  64. $tmp = $v;
  65. $tmp['merchantId'] = $this->sjId;
  66. $tmp['shopId'] = $shopId;
  67. $tmp['adminId'] = $this->adminId;
  68. $productData[] = $tmp;
  69. }
  70. ProductClass::batchAdd($productData);
  71. $transaction->commit();
  72. util::complete();
  73. } catch (\Exception $exception) {
  74. $transaction->rollBack();
  75. util::fail();
  76. }
  77. }
  78. //PC下载微信和支付宝收款码 ssh 2020.2.29
  79. public function actionGatheringCode()
  80. {
  81. $id = Yii::$app->request->get('id', 0);
  82. $shop = ShopService::getById($id);
  83. ShopClass::valid($shop, $this->sjId);
  84. $gatheringCode = ShopClass::generateGatheringCode($this->sjId, $id);
  85. $file = dirUtil::getImgDir() . $gatheringCode;
  86. if (file_exists($file) == false) {
  87. util::fail('没有找到收款码');
  88. }
  89. if (httpUtil::isMiniProgram()) {
  90. $imgUrl = imgUtil::getPrefix() . $gatheringCode;
  91. util::success(['imgUrl' => $imgUrl]);
  92. }
  93. $fileName = "门店({$id})收款码.jpg";
  94. $contentType = 'image/jpeg';
  95. header("Cache-control: private");
  96. header("Content-type: $contentType"); //设置要下载的文件类型
  97. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  98. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  99. readfile($file);
  100. }
  101. //PC获取小程序的收款码 ssh
  102. public function actionGatheringMiniCode()
  103. {
  104. $id = Yii::$app->request->get('id', 0);
  105. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  106. if ($extend['miniAuth'] == 0) {
  107. util::fail('您的小程序还没有授权');
  108. }
  109. $shop = ShopService::getById($id);
  110. ShopClass::valid($shop, $this->sjId);
  111. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj, $id);
  112. $file = dirUtil::getImgDir() . $applyMemberCode;
  113. if (file_exists($file) == false) {
  114. util::fail('没有找到注册会员码');
  115. }
  116. if (httpUtil::isMiniProgram()) {
  117. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  118. util::success(['imgUrl' => $imgUrl]);
  119. }
  120. $fileName = "门店({$id})小程序收款码.jpg";
  121. $contentType = 'image/jpeg';
  122. header("Cache-control: private");
  123. header("Content-type: $contentType"); //设置要下载的文件类型
  124. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  125. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  126. readfile($file);
  127. }
  128. //PC下载会员注册码 ssh 2020.2.29
  129. public function actionApplyMemberCode()
  130. {
  131. $id = Yii::$app->request->get('id', 0);
  132. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  133. if ($extend['miniAuth'] == 0) {
  134. util::fail('您的小程序还没有授权');
  135. }
  136. $shop = ShopService::getById($id);
  137. ShopClass::valid($shop, $this->sjId);
  138. $applyMemberCode = wxUtil::generateMemberCode($this->sj, $id);
  139. $file = dirUtil::getImgDir() . $applyMemberCode;
  140. if (file_exists($file) == false) {
  141. util::fail('没有找到注册会员码');
  142. }
  143. if (httpUtil::isMiniProgram()) {
  144. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  145. util::success(['imgUrl' => $imgUrl]);
  146. }
  147. $fileName = "注册会员码{$id}.jpg";
  148. $contentType = 'image/jpeg';
  149. header("Cache-control: private");
  150. header("Content-type: $contentType"); //设置要下载的文件类型
  151. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  152. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  153. readfile($file);
  154. }
  155. //删除门店 ssh 2020.3.1
  156. public function actionDelete()
  157. {
  158. $id = Yii::$app->request->get('id', 0);
  159. $shop = ShopService::getById($id);
  160. ShopClass::valid($shop, $this->sjId);
  161. ShopClass::deleteShop($shop);
  162. util::complete();
  163. }
  164. //获取所有门店linqh 2021.1.31
  165. public function actionAll()
  166. {
  167. $res = [];
  168. $shopAdmin = $this->shopAdmin;
  169. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  170. $res = ShopClass::getAllShop($this->sjId);
  171. }
  172. util::success($res);
  173. }
  174. //切换门店 linqh 2021.1.31
  175. public function actionToggleShop()
  176. {
  177. $shopId = Yii::$app->request->post('shopId', 0);
  178. $res = AdminClass::toggleShop($this->admin, $shopId, $this->sjId, $this->shopAdmin);
  179. util::success($res);
  180. }
  181. //提现信息更新 ssh 2021.3.23
  182. public function actionCashUpdate()
  183. {
  184. $get = Yii::$app->request->get();
  185. $cashAccount = $get['cashAccount'] ?? '';
  186. $cashName = $get['cashName'] ?? '';
  187. if (empty($cashName)) {
  188. util::fail('请填写姓名');
  189. }
  190. if (empty($cashAccount)) {
  191. util::fail('请填写帐号');
  192. }
  193. $shopAdmin = $this->shopAdmin;
  194. $shopId = $shopAdmin['shopId'];
  195. if ($shopAdmin['super'] != 1) {
  196. util::fail('您没有权限修改');
  197. }
  198. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName]);
  199. util::complete();
  200. }
  201. //获取门店详情 ssh 2021.4.23
  202. public function actionDetail()
  203. {
  204. $shopId = Yii::$app->request->get('shopId');
  205. if (empty($shopId)) {
  206. $shopId = $this->shopId;
  207. }
  208. $shop = ShopClass::getShopInfo($shopId);
  209. util::success(['info' => $shop]);
  210. }
  211. }