GhsController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <?php
  2. namespace hd\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\recharge\classes\RechargeHbClass;
  5. use biz\shop\classes\ShopClass;
  6. use bizGhs\custom\classes\CustomClass;
  7. use bizGhs\custom\classes\CustomLevelClass;
  8. use bizGhs\merchant\classes\WlClass;
  9. use bizHd\purchase\classes\PurchaseClass;
  10. use bizHd\stat\classes\StatVisitClass;
  11. use common\components\dict;
  12. use common\components\imgUtil;
  13. use common\components\qrCodeUtil;
  14. use common\components\stringUtil;
  15. use common\components\util;
  16. use Yii;
  17. class GhsController extends BaseController
  18. {
  19. public $guestAccess = ['info', 'get-ghs-data'];
  20. public static $levelMap = [
  21. 'pt' => ['name' => '普店', 'num' => 0, 'amount' => 0, 'key' => ''],
  22. 'hj' => ['name' => '银店', 'num' => 0, 'amount' => 0, 'key' => 'hj'],
  23. 'zs' => ['name' => '金店', 'num' => 0, 'amount' => 0, 'key' => 'zs'],
  24. ];
  25. //未登录获取供货商信息 ssh 20240507
  26. public function actionGetGhsData()
  27. {
  28. $get = Yii::$app->request->get();
  29. $id = $get['id'] ?? 0;
  30. $salt = $get['salt'] ?? '';
  31. $ghs = GhsClass::getById($id);
  32. if (empty($ghs)) {
  33. util::fail('没有找到供货商的信息哦');
  34. }
  35. if (isset($ghs['salt']) == false || $ghs['salt'] != $salt) {
  36. util::fail('不是您的供货商');
  37. }
  38. $debtAmount = $ghs['debtAmount'] ?? 0;
  39. $balance = $ghs['balance'] ?? 0;
  40. $remainDebtAmount = bcsub($debtAmount, $balance, 2);
  41. $remainDebtAmount = floatval($remainDebtAmount);
  42. $customId = $ghs['customId'] ?? 0;
  43. $custom = CustomClass::getById($customId);
  44. if (empty($custom)) {
  45. util::fail('供货商信息不完整');
  46. }
  47. $ghs['remainDebtAmount'] = $remainDebtAmount;
  48. $custom['remainDebtAmount'] = $remainDebtAmount;
  49. //有同个地方要同步修改,关键词 custom_go_ghs_gathering_code
  50. if (getenv('YII_ENV') == 'production') {
  51. $url = "https://mall.huahb.cn/#/admin/ghs/pay?id={$id}&salt={$salt}";
  52. } else {
  53. $url = "https://mall.huaml.com/#/admin/ghs/pay?id={$id}&salt={$salt}";
  54. }
  55. $unique = "recharge_to_ghs_" . $id;
  56. $imgUrl = qrCodeUtil::generateRechargeQrCode($url, $unique);
  57. $imageUrl = imgUtil::groupImg($imgUrl);
  58. util::success(['ghs' => $ghs, 'custom' => $custom, 'imgUrl' => $imageUrl]);
  59. }
  60. //获取物流列表 ssh 20230608
  61. public function actionGetWlList()
  62. {
  63. $get = Yii::$app->request->get();
  64. $id = $get['id'] ?? 0;
  65. $ghs = GhsClass::getById($id, true);
  66. if (empty($ghs)) {
  67. util::success(['list' => []]);
  68. }
  69. $mainId = $ghs->mainId ?? 0;
  70. $list = WlClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0], null, '*');
  71. util::success(['list' => $list]);
  72. }
  73. //添加虚拟的供货商 ssh 20230305
  74. public function actionAddGhs()
  75. {
  76. util::fail('开发中,即将上线');
  77. $post = Yii::$app->request->post();
  78. $name = $post['name'] ?? '';
  79. if (empty($name)) {
  80. util::fail('请填写名称');
  81. }
  82. if (stringUtil::getWordNum($name) > 8) {
  83. util::fail('名称不能超过8个汉字');
  84. }
  85. $connection = Yii::$app->db;
  86. $transaction = $connection->beginTransaction();
  87. try {
  88. $shopId = $this->shopId;
  89. $has = GhsClass::getByCondition(['ownShopId' => $shopId, 'name' => $name], true);
  90. if (!empty($has)) {
  91. util::fail($name . ' 已经存在了');
  92. }
  93. \bizHd\ghs\services\GhsService::addVirtualGhs($post, $this->shop);
  94. $transaction->commit();
  95. util::complete('添加成功');
  96. } catch (\Exception $e) {
  97. $transaction->rollBack();
  98. Yii::error("添加失败原因:" . $e->getMessage());
  99. util::fail('添加失败');
  100. }
  101. }
  102. //是否屏蔽 ssh 20230226
  103. public function actionChangeDelStatus()
  104. {
  105. $get = Yii::$app->request->get();
  106. $ghsId = $get['ghsId'] ?? 0;
  107. $delStatus = $get['delStatus'] ?? 0;
  108. $ghs = GhsClass::getById($ghsId, true);
  109. if (empty($ghs)) {
  110. util::fail('没有找到供货商');
  111. }
  112. $ownMainId = $ghs->ownMainId ?? 0;
  113. if ($ownMainId != $this->mainId) {
  114. util::fail('无法操作');
  115. }
  116. $ghs->delStatus = $delStatus;
  117. $ghs->save();
  118. util::complete('操作成功');
  119. }
  120. //获取供货商物流 ssh 20230105
  121. public function actionGetAllWl()
  122. {
  123. $get = Yii::$app->request->get();
  124. $id = $get['id'] ?? 0;
  125. $ghs = GhsClass::getById($id, true);
  126. if (empty($ghs) || $ghs->ownMainId != $this->mainId) {
  127. util::success(['list' => []]);
  128. }
  129. $ghsMainId = $ghs->mainId ?? 0;
  130. $list = \bizGhs\merchant\classes\WlClass::getAllByCondition(['mainId' => $ghsMainId, 'delStatus' => 0], 'inTurn DESC', 'id,name');
  131. util::success(['list' => $list]);
  132. }
  133. //采购选分类有变化通知
  134. public function actionGetClassRemind()
  135. {
  136. $cacheKey = 'class_change_remind_' . $this->shopAdminId;
  137. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  138. $hasStatus = !empty($has) ? 1 : 0;
  139. util::success(['hasRemind' => $hasStatus]);
  140. }
  141. //采购选分类有变化通知
  142. public function actionHasClassRemind()
  143. {
  144. $cacheKey = 'class_change_remind_' . $this->shopAdminId;
  145. Yii::$app->redis->executeCommand('SET', [$cacheKey, 'has']);
  146. util::complete();
  147. }
  148. //供货商列表 ssh 2021.1.24
  149. public function actionList()
  150. {
  151. $get = Yii::$app->request->get();
  152. $delStatus = isset($get['delStatus']) && is_numeric($get['delStatus']) ? $get['delStatus'] : 0;
  153. $where = [];
  154. $where['ownShopId'] = $this->shopId;
  155. $where['delStatus'] = $delStatus;
  156. $name = isset($get['name']) ? $get['name'] : '';
  157. if (stringUtil::isLetter($name)) {
  158. $where['py'] = ['like', $name];
  159. } else {
  160. $where['name'] = ['like', $name];
  161. }
  162. $respond = GhsClass::getGhsList($where);
  163. //广告列表
  164. $apiHost = Yii::$app->params['hdImgHost'];
  165. //$ad = [['banner' => $apiHost . '/ljh/banner2.jpg', 'url' => '/admin/ljh/info']];
  166. $ad = [];
  167. $respond['ad'] = $ad;
  168. //默认显示广告
  169. $showAd = 1;
  170. if (isset($respond['list']) && !empty($respond['list'])) {
  171. foreach ($respond['list'] as $key => $ghs) {
  172. if (getenv('YII_ENV') == 'production') {
  173. //海翔、源花汇先不显示广告
  174. $noAdShopId = [42345, 10649];
  175. } else {
  176. $noAdShopId = [0];
  177. }
  178. if (isset($ghs['shopId']) && in_array($ghs['shopId'], $noAdShopId)) {
  179. $showAd = 0;
  180. }
  181. }
  182. }
  183. $respond['showAd'] = $showAd;
  184. //告之你有多家供货商了
  185. $list = $respond['list'] ?? [];
  186. if (count($list) > 1) {
  187. $admin = $this->admin;
  188. $noticeHasMoreGhs = $admin->noticeHasMoreGhs ?? 0;
  189. if ($noticeHasMoreGhs == 0) {
  190. $respond['needNotice'] = 1;
  191. }
  192. }
  193. util::success($respond);
  194. }
  195. //详情 ssh 2021.4.11
  196. public function actionDetail()
  197. {
  198. $id = Yii::$app->request->get('id');
  199. $info = GhsClass::getGhsInfo($id);
  200. $giveLevel = $info['giveLevel'] ?? 0;
  201. $levelMap = CustomClass::$nickNameMap;
  202. $giveLevelName = $levelMap[$giveLevel] ?? '散客';
  203. $info['giveLevelName'] = $giveLevelName;
  204. GhsClass::valid($info, $this->shopId);
  205. //是否有充值送红包活动
  206. $ghsShopId = $info['shopId'] ?? 0;
  207. $ghsShop = ShopClass::getById($ghsShopId, true);
  208. $info['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  209. $hb = RechargeHbClass::getByCondition(['shopId' => $ghsShopId, 'delStatus' => 0], true, 'totalHb DESC');
  210. $info['hasRechargeHbAmount'] = $hb->totalHb ?? 0;
  211. $info['xrFl'] = $ghsShop->xrFl ?? 0;
  212. $info['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  213. $info['tjFl'] = $ghsShop->tjFl ?? 0;
  214. $info['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  215. $info['packCost'] = $ghsShop->packCost ? floatval($ghsShop->packCost) : 0;
  216. $lackExpend = $ghsShop->lackExpend ? floatval($ghsShop->lackExpend) : 0;
  217. $customId = $info['customId'] ?? 0;
  218. $needAdd = \bizHd\shop\classes\ShopClass::needAddPackCost($ghsShop, $customId);
  219. //昆明批发,需要算打包费和运费
  220. $needAddPackFreight = 1;
  221. if ($needAdd == false) {
  222. $lackExpend = 0;
  223. //昆明批发,不需要算打包费和运费
  224. $needAddPackFreight = 0;
  225. }
  226. $info['needAddPackFreight'] = $needAddPackFreight;
  227. $info['lackExpend'] = $lackExpend;
  228. $info['showSold'] = $ghsShop->showSold ?? 0;
  229. $info['buyNotice'] = $ghsShop->buyNotice ?? 0;
  230. $info['lsShopId'] = $ghsShop->lsShopId ?? 0;
  231. //预订单的最低公斤数和每公斤服务费
  232. $info['kiloFee'] = $ghsShop->kiloFee ?? 0;
  233. $info['miniKilo'] = $ghsShop->miniKilo ?? 0;
  234. $info['pfLevel'] = $ghsShop->pfLevel ?? 0;
  235. $info['afterSale'] = $ghsShop->afterSale ?? 1;
  236. //联系电话
  237. $info['telephone'] = $ghsShop->telephone ?? '';
  238. $shareLogo = imgUtil::groupImg('buy_logo.jpg');
  239. if (isset($ghsShop->shareLogo) && !empty($ghsShop->shareLogo)) {
  240. $shareLogo = imgUtil::groupImg($ghsShop->shareLogo);
  241. }
  242. $info['shareLogo'] = $shareLogo;
  243. $info['superWx'] = '';
  244. if (!empty($ghsShop->superWx)) {
  245. $info['superWx'] = imgUtil::groupImg($ghsShop->superWx). "?x-oss-process=image/resize,w_150";
  246. }
  247. $ghsMainId = $ghsShop->mainId ?? 0;
  248. $kmPackCost = PurchaseClass::getKmPackCost($ghsMainId);
  249. $info['kmPackCost'] = $kmPackCost;
  250. $info['transCost'] = dict::getDict('transCost', null, null, $ghsShop->mainId);
  251. //杭州斗南鲜花批发 免运费活动
  252. if (isset($info['shopId']) && $info['shopId'] == 4608) {
  253. $current = time();
  254. if ($current < strtotime('2023-4-8 00:00:00')) {
  255. $info['hasAct'] = 1;
  256. }
  257. }
  258. util::success($info);
  259. }
  260. //根据门店获取供货商信息 ssh 2021.4.14
  261. public function actionInfo()
  262. {
  263. $shopId = Yii::$app->request->get('shopId');
  264. if (isset($this->shopId) && !empty($this->shopId)) {
  265. $current = ShopClass::getById($shopId, true);
  266. if (isset($current->ptStyle) == false || $current->ptStyle != dict::getDict('ptStyle', 'ghs')) {
  267. util::fail('没有找到批发店');
  268. }
  269. $ghs = GhsClass::build($shopId, $this->shopId);
  270. //是否有充值送红包活动
  271. $ghsShopId = $ghs['shopId'] ?? 0;
  272. $ghsShop = ShopClass::getById($ghsShopId, true);
  273. $ghs['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  274. $hb = RechargeHbClass::getByCondition(['shopId' => $ghsShopId, 'delStatus' => 0], true, 'totalHb DESC');
  275. $ghs['hasRechargeHbAmount'] = $hb->totalHb ?? 0;
  276. $avatar = $ghs['avatar'] ?? '';
  277. $ghs['avatar'] = imgUtil::groupImg($avatar);
  278. $map = CustomClass::$nickNameMap;
  279. $giveLevel = $ghs['giveLevel'] ?? 0;
  280. $ghs['giveLevelName'] = $map[$giveLevel] ?? '';
  281. $ghs['showSold'] = $ghsShop->showSold ?? 0;
  282. $ghs['buyNotice'] = $ghsShop->buyNotice ?? 0;
  283. $ghs['xrFl'] = $ghsShop->xrFl ?? 0;
  284. $ghs['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  285. $ghs['tjFl'] = $ghsShop->tjFl ?? 0;
  286. $ghs['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  287. $ghs['lsShopId'] = $ghsShop->lsShopId ?? 0;
  288. $ghs['presell'] = $ghsShop->presell ?? 0;
  289. $shareLogo = imgUtil::groupImg('buy_logo.jpg');
  290. if (isset($ghsShop->shareLogo) && !empty($ghsShop->shareLogo)) {
  291. $shareLogo = imgUtil::groupImg($ghsShop->shareLogo);
  292. }
  293. $ghs['shareLogo'] = $shareLogo;
  294. $ghs['telephone'] = $ghsShop->telephone ?? '';
  295. $ghs['superWx'] = '';
  296. if (!empty($ghsShop->superWx)) {
  297. $ghs['superWx'] = imgUtil::groupImg($ghsShop->superWx);
  298. }
  299. $ghs['transCost'] = dict::getDict('transCost', null, null, $ghsShop->mainId);
  300. } else {
  301. //没有开店也给显示供货商信息
  302. $shop = ShopClass::getShopInfo($shopId);
  303. $shopName = $shop['shopName'] ?? '';
  304. $sjName = $shop['merchantName'] ?? '';
  305. $avatar = $shop['avatar'] ?? '';
  306. $default = $shop['default'] ?? 0;
  307. $name = $default == 1 && $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  308. $ghs = [
  309. 'id' => 0,
  310. 'name' => $name,
  311. 'debtAmount' => 0.00,
  312. 'expendAmount' => 0.00,
  313. 'giveLevel' => 0,
  314. 'giveLevelName' => '普通',
  315. 'xrFl' => 0,
  316. 'xrFlAmount' => 0,
  317. 'tjFl' => 0,
  318. 'tjFlAmount' => 0,
  319. 'avatar' => $avatar,
  320. 'showSold' => 0,
  321. 'buyNotice' => 0,
  322. 'lsShopId' => 0,
  323. 'presell' => 0,
  324. 'shareLogo' => '',
  325. 'superWx' => '',
  326. 'transCost' => [],
  327. ];
  328. }
  329. util::success($ghs);
  330. }
  331. //获取客户等级 ssh 20211016
  332. public function actionGetCustomLevel()
  333. {
  334. $id = Yii::$app->request->get('id');
  335. $info = GhsClass::getById($id, true);
  336. GhsClass::valid($info, $this->shopId);
  337. $ghsShopId = $info->shopId ?? 0;
  338. $info = CustomLevelClass::getByCondition(['shopId' => $ghsShopId]);
  339. $map = self::$levelMap;
  340. foreach ($map as $key => $val) {
  341. $flag = $val['key'] ?? '';
  342. if (empty($flag)) {
  343. $map[$key]['num'] = $info["num"] ?? 0;
  344. $map[$key]['amount'] = $info["amount"] ?? 0;
  345. } else {
  346. $map[$key]['num'] = $info[$flag . "Num"] ?? 0;
  347. $map[$key]['amount'] = $info[$flag . "Amount"] ?? 0;
  348. }
  349. }
  350. util::success(['list' => $map]);
  351. }
  352. //访问供货商的商城 ssh 20211022
  353. public function actionVisitMall()
  354. {
  355. $id = Yii::$app->request->get('id');
  356. $info = GhsClass::getById($id, true);
  357. GhsClass::valid($info, $this->shopId);
  358. $customId = $info->customId ?? 0;
  359. $custom = CustomClass::getById($customId, true);
  360. if (empty($custom)) {
  361. util::fail('没有找到客户');
  362. }
  363. StatVisitClass::addGhsCustomVisit($info, $custom);
  364. util::complete();
  365. }
  366. //补充缺失的供货商 ssh 20211027
  367. public function actionBcGhs()
  368. {
  369. util::fail('过几天再试');
  370. GhsClass::bcGhs($this->shopId);
  371. util::complete('载入成功');
  372. }
  373. }