GhsController.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. //预订单的最低公斤数和每公斤服务费
  135. $info['kiloFee'] = $ghsShop->kiloFee ?? 0;
  136. $info['miniKilo'] = $ghsShop->miniKilo ?? 0;
  137. //杭州斗南鲜花批发 免运费活动
  138. if (isset($info['shopId']) && $info['shopId'] == 4608) {
  139. $current = time();
  140. if ($current < strtotime('2023-4-8 00:00:00')) {
  141. $info['hasAct'] = 1;
  142. }
  143. }
  144. util::success($info);
  145. }
  146. //根据门店获取供货商信息 ssh 2021.4.14
  147. public function actionInfo()
  148. {
  149. $shopId = Yii::$app->request->get('shopId');
  150. if (isset($this->shopId) && !empty($this->shopId)) {
  151. $current = ShopClass::getById($shopId, true);
  152. if (isset($current->ptStyle) == false || $current->ptStyle != dict::getDict('ptStyle', 'ghs')) {
  153. util::fail('没有找到批发店');
  154. }
  155. $ghs = GhsClass::build($shopId, $this->shopId);
  156. //是否有充值送红包活动
  157. $ghsShopId = $ghs['shopId'] ?? 0;
  158. $ghsShop = ShopClass::getById($ghsShopId, true);
  159. $ghs['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  160. $hb = RechargeHbClass::getByCondition(['shopId' => $ghsShopId, 'delStatus' => 0], true, 'totalHb DESC');
  161. $ghs['hasRechargeHbAmount'] = $hb->totalHb ?? 0;
  162. $avatar = $ghs['avatar'] ?? '';
  163. $ghs['avatar'] = imgUtil::groupImg($avatar);
  164. $map = CustomClass::$nickNameMap;
  165. $giveLevel = $ghs['giveLevel'] ?? 0;
  166. $ghs['giveLevelName'] = $map[$giveLevel] ?? '';
  167. $ghs['buyNotice'] = $ghsShop->buyNotice ?? 0;
  168. $ghs['xrFl'] = $ghsShop->xrFl ?? 0;
  169. $ghs['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  170. $ghs['tjFl'] = $ghsShop->tjFl ?? 0;
  171. $ghs['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  172. } else {
  173. //没有开店也给显示供货商信息
  174. $shop = ShopClass::getShopInfo($shopId);
  175. $shopName = $shop['shopName'] ?? '';
  176. $sjName = $shop['merchantName'] ?? '';
  177. $avatar = $shop['avatar'] ?? '';
  178. $default = $shop['default'] ?? 0;
  179. $name = $default == 1 && $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  180. $ghs = [
  181. 'id' => 0,
  182. 'name' => $name,
  183. 'debtAmount' => 0.00,
  184. 'expendAmount' => 0.00,
  185. 'giveLevel' => 0,
  186. 'giveLevelName' => '普通',
  187. 'xrFl' => 0,
  188. 'xrFlAmount' => 0,
  189. 'tjFl' => 0,
  190. 'tjFlAmount' => 0,
  191. 'avatar' => $avatar,
  192. 'buyNotice' => 0,
  193. ];
  194. }
  195. util::success($ghs);
  196. }
  197. //获取客户等级 ssh 20211016
  198. public function actionGetCustomLevel()
  199. {
  200. $id = Yii::$app->request->get('id');
  201. $info = GhsClass::getById($id, true);
  202. GhsClass::valid($info, $this->shopId);
  203. $ghsShopId = $info->shopId ?? 0;
  204. $info = CustomLevelClass::getByCondition(['shopId' => $ghsShopId]);
  205. $map = self::$levelMap;
  206. foreach ($map as $key => $val) {
  207. $flag = $val['key'] ?? '';
  208. if (empty($flag)) {
  209. $map[$key]['num'] = $info["num"] ?? 0;
  210. $map[$key]['amount'] = $info["amount"] ?? 0;
  211. } else {
  212. $map[$key]['num'] = $info[$flag . "Num"] ?? 0;
  213. $map[$key]['amount'] = $info[$flag . "Amount"] ?? 0;
  214. }
  215. }
  216. util::success(['list' => $map]);
  217. }
  218. //访问供货商的商城 ssh 20211022
  219. public function actionVisitMall()
  220. {
  221. $id = Yii::$app->request->get('id');
  222. $info = GhsClass::getById($id, true);
  223. GhsClass::valid($info, $this->shopId);
  224. $customId = $info->customId ?? 0;
  225. $custom = CustomClass::getById($customId, true);
  226. if (empty($custom)) {
  227. util::fail('没有找到客户');
  228. }
  229. StatVisitClass::addGhsCustomVisit($info, $custom);
  230. util::complete();
  231. }
  232. //补充缺失的供货商 ssh 20211027
  233. public function actionBcGhs()
  234. {
  235. util::fail('过几天再试');
  236. GhsClass::bcGhs($this->shopId);
  237. util::complete('载入成功');
  238. }
  239. }