GhsController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. $respond = GhsClass::getGhsList($where);
  157. //广告列表
  158. $apiHost = Yii::$app->params['hdImgHost'];
  159. //$ad = [['banner' => $apiHost . '/ljh/banner2.jpg', 'url' => '/admin/ljh/info']];
  160. $ad = [];
  161. $respond['ad'] = $ad;
  162. util::success($respond);
  163. }
  164. //详情 ssh 2021.4.11
  165. public function actionDetail()
  166. {
  167. $id = Yii::$app->request->get('id');
  168. $info = GhsClass::getGhsInfo($id);
  169. $giveLevel = $info['giveLevel'] ?? 0;
  170. $levelMap = CustomClass::$nickNameMap;
  171. $giveLevelName = $levelMap[$giveLevel] ?? '散客';
  172. $info['giveLevelName'] = $giveLevelName;
  173. GhsClass::valid($info, $this->shopId);
  174. //是否有充值送红包活动
  175. $ghsShopId = $info['shopId'] ?? 0;
  176. $ghsShop = ShopClass::getById($ghsShopId, true);
  177. $info['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  178. $hb = RechargeHbClass::getByCondition(['shopId' => $ghsShopId, 'delStatus' => 0], true, 'totalHb DESC');
  179. $info['hasRechargeHbAmount'] = $hb->totalHb ?? 0;
  180. $info['xrFl'] = $ghsShop->xrFl ?? 0;
  181. $info['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  182. $info['tjFl'] = $ghsShop->tjFl ?? 0;
  183. $info['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  184. $info['packCost'] = $ghsShop->packCost ? floatval($ghsShop->packCost) : 0;
  185. $lackExpend = $ghsShop->lackExpend ? floatval($ghsShop->lackExpend) : 0;
  186. $customId = $info['customId'] ?? 0;
  187. $needAdd = \bizHd\shop\classes\ShopClass::needAddPackCost($ghsShop, $customId);
  188. //昆明批发,需要算打包费和运费
  189. $needAddPackFreight = 1;
  190. if ($needAdd == false) {
  191. $lackExpend = 0;
  192. //昆明批发,不需要算打包费和运费
  193. $needAddPackFreight = 0;
  194. }
  195. $info['needAddPackFreight'] = $needAddPackFreight;
  196. $info['lackExpend'] = $lackExpend;
  197. $info['showSold'] = $ghsShop->showSold ?? 0;
  198. $info['buyNotice'] = $ghsShop->buyNotice ?? 0;
  199. $info['lsShopId'] = $ghsShop->lsShopId ?? 0;
  200. //预订单的最低公斤数和每公斤服务费
  201. $info['kiloFee'] = $ghsShop->kiloFee ?? 0;
  202. $info['miniKilo'] = $ghsShop->miniKilo ?? 0;
  203. $info['pfLevel'] = $ghsShop->pfLevel ?? 0;
  204. $info['afterSale'] = $ghsShop->afterSale ?? 1;
  205. //联系电话
  206. $info['telephone'] = $ghsShop->telephone ?? '';
  207. $shareLogo = imgUtil::groupImg('buy_logo.jpg');
  208. if (isset($ghsShop->shareLogo) && !empty($ghsShop->shareLogo)) {
  209. $shareLogo = imgUtil::groupImg($ghsShop->shareLogo);
  210. }
  211. $info['shareLogo'] = $shareLogo;
  212. $info['superWx'] = '';
  213. if (!empty($ghsShop->superWx)) {
  214. $info['superWx'] = imgUtil::groupImg($ghsShop->superWx);
  215. }
  216. $ghsMainId = $ghsShop->mainId ?? 0;
  217. $kmPackCost = PurchaseClass::getKmPackCost($ghsMainId);
  218. $info['kmPackCost'] = $kmPackCost;
  219. $info['transCost'] = dict::getDict('transCost', null, null, $ghsShop->mainId);
  220. //杭州斗南鲜花批发 免运费活动
  221. if (isset($info['shopId']) && $info['shopId'] == 4608) {
  222. $current = time();
  223. if ($current < strtotime('2023-4-8 00:00:00')) {
  224. $info['hasAct'] = 1;
  225. }
  226. }
  227. util::success($info);
  228. }
  229. //根据门店获取供货商信息 ssh 2021.4.14
  230. public function actionInfo()
  231. {
  232. $shopId = Yii::$app->request->get('shopId');
  233. if (isset($this->shopId) && !empty($this->shopId)) {
  234. $current = ShopClass::getById($shopId, true);
  235. if (isset($current->ptStyle) == false || $current->ptStyle != dict::getDict('ptStyle', 'ghs')) {
  236. util::fail('没有找到批发店');
  237. }
  238. $ghs = GhsClass::build($shopId, $this->shopId);
  239. //是否有充值送红包活动
  240. $ghsShopId = $ghs['shopId'] ?? 0;
  241. $ghsShop = ShopClass::getById($ghsShopId, true);
  242. $ghs['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  243. $hb = RechargeHbClass::getByCondition(['shopId' => $ghsShopId, 'delStatus' => 0], true, 'totalHb DESC');
  244. $ghs['hasRechargeHbAmount'] = $hb->totalHb ?? 0;
  245. $avatar = $ghs['avatar'] ?? '';
  246. $ghs['avatar'] = imgUtil::groupImg($avatar);
  247. $map = CustomClass::$nickNameMap;
  248. $giveLevel = $ghs['giveLevel'] ?? 0;
  249. $ghs['giveLevelName'] = $map[$giveLevel] ?? '';
  250. $ghs['showSold'] = $ghsShop->showSold ?? 0;
  251. $ghs['buyNotice'] = $ghsShop->buyNotice ?? 0;
  252. $ghs['xrFl'] = $ghsShop->xrFl ?? 0;
  253. $ghs['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  254. $ghs['tjFl'] = $ghsShop->tjFl ?? 0;
  255. $ghs['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  256. $ghs['lsShopId'] = $ghsShop->lsShopId ?? 0;
  257. $ghs['presell'] = $ghsShop->presell ?? 0;
  258. $shareLogo = imgUtil::groupImg('buy_logo.jpg');
  259. if (isset($ghsShop->shareLogo) && !empty($ghsShop->shareLogo)) {
  260. $shareLogo = imgUtil::groupImg($ghsShop->shareLogo);
  261. }
  262. $ghs['shareLogo'] = $shareLogo;
  263. $ghs['superWx'] = '';
  264. if(!empty($ghsShop->superWx)){
  265. $ghs['superWx'] = imgUtil::groupImg($ghsShop->superWx);
  266. }
  267. $ghs['transCost'] = dict::getDict('transCost', null, null, $ghsShop->mainId);
  268. } else {
  269. //没有开店也给显示供货商信息
  270. $shop = ShopClass::getShopInfo($shopId);
  271. $shopName = $shop['shopName'] ?? '';
  272. $sjName = $shop['merchantName'] ?? '';
  273. $avatar = $shop['avatar'] ?? '';
  274. $default = $shop['default'] ?? 0;
  275. $name = $default == 1 && $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  276. $ghs = [
  277. 'id' => 0,
  278. 'name' => $name,
  279. 'debtAmount' => 0.00,
  280. 'expendAmount' => 0.00,
  281. 'giveLevel' => 0,
  282. 'giveLevelName' => '普通',
  283. 'xrFl' => 0,
  284. 'xrFlAmount' => 0,
  285. 'tjFl' => 0,
  286. 'tjFlAmount' => 0,
  287. 'avatar' => $avatar,
  288. 'showSold' => 0,
  289. 'buyNotice' => 0,
  290. 'lsShopId' => 0,
  291. 'presell' => 0,
  292. 'shareLogo' => '',
  293. 'superWx' => '',
  294. 'transCost' => [],
  295. ];
  296. }
  297. util::success($ghs);
  298. }
  299. //获取客户等级 ssh 20211016
  300. public function actionGetCustomLevel()
  301. {
  302. $id = Yii::$app->request->get('id');
  303. $info = GhsClass::getById($id, true);
  304. GhsClass::valid($info, $this->shopId);
  305. $ghsShopId = $info->shopId ?? 0;
  306. $info = CustomLevelClass::getByCondition(['shopId' => $ghsShopId]);
  307. $map = self::$levelMap;
  308. foreach ($map as $key => $val) {
  309. $flag = $val['key'] ?? '';
  310. if (empty($flag)) {
  311. $map[$key]['num'] = $info["num"] ?? 0;
  312. $map[$key]['amount'] = $info["amount"] ?? 0;
  313. } else {
  314. $map[$key]['num'] = $info[$flag . "Num"] ?? 0;
  315. $map[$key]['amount'] = $info[$flag . "Amount"] ?? 0;
  316. }
  317. }
  318. util::success(['list' => $map]);
  319. }
  320. //访问供货商的商城 ssh 20211022
  321. public function actionVisitMall()
  322. {
  323. $id = Yii::$app->request->get('id');
  324. $info = GhsClass::getById($id, true);
  325. GhsClass::valid($info, $this->shopId);
  326. $customId = $info->customId ?? 0;
  327. $custom = CustomClass::getById($customId, true);
  328. if (empty($custom)) {
  329. util::fail('没有找到客户');
  330. }
  331. StatVisitClass::addGhsCustomVisit($info, $custom);
  332. util::complete();
  333. }
  334. //补充缺失的供货商 ssh 20211027
  335. public function actionBcGhs()
  336. {
  337. util::fail('过几天再试');
  338. GhsClass::bcGhs($this->shopId);
  339. util::complete('载入成功');
  340. }
  341. }