GhsController.php 11 KB

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