GhsController.php 8.2 KB

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