GhsController.php 13 KB

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