GhsController.php 9.5 KB

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