GhsController.php 11 KB

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