GhsController.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. $shopId = $this->shopId;
  34. $has = GhsClass::getByCondition(['ownShopId' => $shopId, 'name' => $name], true);
  35. if (!empty($has)) {
  36. util::fail($name . ' 已经存在了');
  37. }
  38. \bizHd\ghs\services\GhsService::addVirtualGhs($post, $this->shop);
  39. util::complete();
  40. }
  41. //是否屏蔽 ssh 20230226
  42. public function actionChangeDelStatus()
  43. {
  44. $get = Yii::$app->request->get();
  45. $ghsId = $get['ghsId'] ?? 0;
  46. $delStatus = $get['delStatus'] ?? 0;
  47. $ghs = GhsClass::getById($ghsId, true);
  48. if (empty($ghs)) {
  49. util::fail('没有找到供货商');
  50. }
  51. $ownMainId = $ghs->ownMainId ?? 0;
  52. if ($ownMainId != $this->mainId) {
  53. util::fail('没有权限操作');
  54. }
  55. $ghs->delStatus = $delStatus;
  56. $ghs->save();
  57. util::complete('操作成功');
  58. }
  59. //获取供货商物流 ssh 20230105
  60. public function actionGetAllWl()
  61. {
  62. $get = Yii::$app->request->get();
  63. $id = $get['id'] ?? 0;
  64. $ghs = GhsClass::getById($id, true);
  65. if (empty($ghs) || $ghs->ownMainId != $this->mainId) {
  66. util::success(['list' => []]);
  67. }
  68. $ghsMainId = $ghs->mainId ?? 0;
  69. $list = \bizGhs\merchant\classes\WlClass::getAllByCondition(['mainId' => $ghsMainId, 'delStatus' => 0], 'inTurn DESC', 'id,name');
  70. util::success(['list' => $list]);
  71. }
  72. //采购选分类有变化通知
  73. public function actionGetClassRemind()
  74. {
  75. $cacheKey = 'class_change_remind_' . $this->shopAdminId;
  76. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  77. $hasStatus = !empty($has) ? 1 : 0;
  78. util::success(['hasRemind' => $hasStatus]);
  79. }
  80. //采购选分类有变化通知
  81. public function actionHasClassRemind()
  82. {
  83. $cacheKey = 'class_change_remind_' . $this->shopAdminId;
  84. Yii::$app->redis->executeCommand('SET', [$cacheKey, 'has']);
  85. util::complete();
  86. }
  87. //供货商列表 ssh 2021.1.24
  88. public function actionList()
  89. {
  90. $get = Yii::$app->request->get();
  91. $delStatus = isset($get['delStatus']) && is_numeric($get['delStatus']) ? $get['delStatus'] : 0;
  92. $where = [];
  93. $where['ownShopId'] = $this->shopId;
  94. $where['delStatus'] = $delStatus;
  95. $respond = GhsClass::getGhsList($where);
  96. util::success($respond);
  97. }
  98. //详情 ssh 2021.4.11
  99. public function actionDetail()
  100. {
  101. $id = Yii::$app->request->get('id');
  102. $info = GhsClass::getGhsInfo($id);
  103. $giveLevel = $info['giveLevel'] ?? 0;
  104. $levelMap = CustomClass::$nickNameMap;
  105. $giveLevelName = $levelMap[$giveLevel] ?? '散客';
  106. $info['giveLevelName'] = $giveLevelName;
  107. GhsClass::valid($info, $this->shopId);
  108. //是否有充值送红包活动
  109. $ghsShopId = $info['shopId'] ?? 0;
  110. $ghsShop = ShopClass::getById($ghsShopId, true);
  111. $info['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  112. $hb = RechargeHbClass::getByCondition(['shopId' => $ghsShopId, 'delStatus' => 0], true, 'totalHb DESC');
  113. $info['hasRechargeHbAmount'] = $hb->totalHb ?? 0;
  114. $info['xrFl'] = $ghsShop->xrFl ?? 0;
  115. $info['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  116. $info['tjFl'] = $ghsShop->tjFl ?? 0;
  117. $info['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  118. $info['packCost'] = $ghsShop->packCost ?? 0;
  119. $info['buyNotice'] = $ghsShop->buyNotice ?? 0;
  120. //预订单的最低公斤数和每公斤服务费
  121. $info['kiloFee'] = $ghsShop->kiloFee ?? 0;
  122. $info['miniKilo'] = $ghsShop->miniKilo ?? 0;
  123. util::success($info);
  124. }
  125. //根据门店获取供货商信息 ssh 2021.4.14
  126. public function actionInfo()
  127. {
  128. $shopId = Yii::$app->request->get('shopId');
  129. if (isset($this->shopId) && !empty($this->shopId)) {
  130. $current = ShopClass::getById($shopId, true);
  131. if (isset($current->ptStyle) == false || $current->ptStyle != dict::getDict('ptStyle', 'ghs')) {
  132. util::fail('没有找到批发店');
  133. }
  134. $ghs = GhsClass::build($shopId, $this->shopId);
  135. //是否有充值送红包活动
  136. $ghsShopId = $ghs['shopId'] ?? 0;
  137. $ghsShop = ShopClass::getById($ghsShopId, true);
  138. $ghs['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  139. $hb = RechargeHbClass::getByCondition(['shopId' => $ghsShopId, 'delStatus' => 0], true, 'totalHb DESC');
  140. $ghs['hasRechargeHbAmount'] = $hb->totalHb ?? 0;
  141. $avatar = $ghs['avatar'] ?? '';
  142. $ghs['avatar'] = imgUtil::groupImg($avatar);
  143. $map = CustomClass::$nickNameMap;
  144. $giveLevel = $ghs['giveLevel'] ?? 0;
  145. $ghs['giveLevelName'] = $map[$giveLevel] ?? '';
  146. $ghs['buyNotice'] = $ghsShop->buyNotice ?? 0;
  147. $ghs['xrFl'] = $ghsShop->xrFl ?? 0;
  148. $ghs['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  149. $ghs['tjFl'] = $ghsShop->tjFl ?? 0;
  150. $ghs['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  151. } else {
  152. //没有开店也给显示供货商信息
  153. $shop = ShopClass::getShopInfo($shopId);
  154. $shopName = $shop['shopName'] ?? '';
  155. $sjName = $shop['merchantName'] ?? '';
  156. $avatar = $shop['avatar'] ?? '';
  157. $default = $shop['default'] ?? 0;
  158. $name = $default == 1 && $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  159. $ghs = [
  160. 'id' => 0,
  161. 'name' => $name,
  162. 'debtAmount' => 0.00,
  163. 'expendAmount' => 0.00,
  164. 'giveLevel' => 0,
  165. 'giveLevelName' => '普通',
  166. 'xrFl' => 0,
  167. 'xrFlAmount' => 0,
  168. 'tjFl' => 0,
  169. 'tjFlAmount' => 0,
  170. 'avatar' => $avatar,
  171. 'buyNotice' => 0,
  172. ];
  173. }
  174. util::success($ghs);
  175. }
  176. //获取客户等级 ssh 20211016
  177. public function actionGetCustomLevel()
  178. {
  179. $id = Yii::$app->request->get('id');
  180. $info = GhsClass::getById($id, true);
  181. GhsClass::valid($info, $this->shopId);
  182. $ghsShopId = $info->shopId ?? 0;
  183. $info = CustomLevelClass::getByCondition(['shopId' => $ghsShopId]);
  184. $map = self::$levelMap;
  185. foreach ($map as $key => $val) {
  186. $flag = $val['key'] ?? '';
  187. if (empty($flag)) {
  188. $map[$key]['num'] = $info["num"] ?? 0;
  189. $map[$key]['amount'] = $info["amount"] ?? 0;
  190. } else {
  191. $map[$key]['num'] = $info[$flag . "Num"] ?? 0;
  192. $map[$key]['amount'] = $info[$flag . "Amount"] ?? 0;
  193. }
  194. }
  195. util::success(['list' => $map]);
  196. }
  197. //访问供货商的商城 ssh 20211022
  198. public function actionVisitMall()
  199. {
  200. $id = Yii::$app->request->get('id');
  201. $info = GhsClass::getById($id, true);
  202. GhsClass::valid($info, $this->shopId);
  203. $customId = $info->customId ?? 0;
  204. $custom = CustomClass::getById($customId, true);
  205. if (empty($custom)) {
  206. util::fail('没有找到客户');
  207. }
  208. StatVisitClass::addGhsCustomVisit($info, $custom);
  209. util::complete();
  210. }
  211. //补充缺失的供货商 ssh 20211027
  212. public function actionBcGhs()
  213. {
  214. util::fail('过几天再试');
  215. GhsClass::bcGhs($this->shopId);
  216. util::complete('载入成功');
  217. }
  218. }