GhsController.php 13 KB

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