GhsController.php 15 KB

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