GhsController.php 15 KB

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