GhsController.php 11 KB

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