GhsController.php 12 KB

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