GhsController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\sj\classes\SjClass;
  4. use bizGhs\ghs\classes\GhsClass;
  5. use bizHd\saas\classes\ApplyClass;
  6. use bizHd\saas\services\ApplyService;
  7. use common\components\dict;
  8. use common\components\imgUtil;
  9. use common\components\orderSn;
  10. use common\components\stringUtil;
  11. use Yii;
  12. use common\components\util;
  13. class GhsController extends BaseController
  14. {
  15. //修改供货商类型 ssh 20240727
  16. public function actionChangeLocation()
  17. {
  18. $get = Yii::$app->request->get();
  19. $id = $get['id'] ?? 0;
  20. $ghs = GhsClass::getById($id, true);
  21. if (empty($ghs)) {
  22. util::fail('没有找到供货商');
  23. }
  24. if ($ghs->ownMainId != $this->mainId) {
  25. util::fail('不是你的供货商');
  26. }
  27. $newLocation = $ghs->location == 0 ? 1 : 0;
  28. $ghs->location = $newLocation;
  29. $ghs->save();
  30. util::complete('修改成功');
  31. }
  32. //修改供货商屏蔽/删除状态 ssh 20260527
  33. public function actionChangeDelStatus()
  34. {
  35. $get = Yii::$app->request->get();
  36. $ghsId = $get['ghsId'] ?? 0;
  37. $delStatus = $get['delStatus'] ?? 0;
  38. $ghs = GhsClass::getById($ghsId, true);
  39. if (empty($ghs)) {
  40. util::fail('没有找到供货商');
  41. }
  42. $ownMainId = $ghs->ownMainId ?? 0;
  43. if ($ownMainId != $this->mainId) {
  44. util::fail('不是你的供货商,无法操作');
  45. }
  46. $ghs->delStatus = $delStatus;
  47. $ghs->save();
  48. util::complete('操作成功');
  49. }
  50. public function actionModifyName()
  51. {
  52. $get = Yii::$app->request->get();
  53. $id = $get['id'] ?? 0;
  54. $name = $get['name'] ?? '';
  55. $ghs = GhsClass::getById($id, true);
  56. if (empty($ghs)) {
  57. util::fail('没有找到供货商');
  58. }
  59. if ($ghs->ownMainId != $this->mainId) {
  60. util::fail('不是你的供货商');
  61. }
  62. if (empty($name)) {
  63. util::fail('请填写名称');
  64. }
  65. if (stringUtil::getWordNum($name) > 27) {
  66. util::fail('名称不能超过27个汉字');
  67. }
  68. $ghs->name = $name;
  69. $ghs->py = stringUtil::py($name);
  70. $ghs->save();
  71. util::complete('修改成功');
  72. }
  73. /**
  74. * 【用途】供货商列表「待结笔数刷新」:按采购挂账单重算并回写 debtNum。
  75. * GET id=供货商id
  76. */
  77. public function actionRefreshDebtNum()
  78. {
  79. $get = Yii::$app->request->get();
  80. $id = intval($get['id'] ?? 0);
  81. $ghs = GhsClass::getById($id, true);
  82. if (empty($ghs)) {
  83. util::fail('没有找到供货商');
  84. }
  85. if ($ghs->ownMainId != $this->mainId) {
  86. util::fail('不是你的供货商');
  87. }
  88. $debtNum = GhsClass::refreshDebtNum($id);
  89. if ($debtNum < 0) {
  90. util::fail('刷新失败');
  91. }
  92. util::success(['debtNum' => $debtNum]);
  93. }
  94. //添加供货商 ssh 20210611
  95. public function actionAdd()
  96. {
  97. $post = Yii::$app->request->post();
  98. $location = $post['location'] ?? '';
  99. $mobile = $post['mobile'] ?? '';
  100. $name = $post['name'] ?? '';
  101. if (empty($name)) {
  102. util::fail('名称不能为空');
  103. }
  104. if (stringUtil::getWordNum($name) > 27) {
  105. util::fail('名称不能超过27个汉字');
  106. }
  107. $hasGhsList = GhsClass::getAllByCondition(['ownShopId' => $this->shopId], null, '*', null, true);
  108. if (!empty($hasGhsList)) {
  109. foreach ($hasGhsList as $hasGhs) {
  110. $hasGhsName = $hasGhs->name ?? '';
  111. if ($hasGhsName == $name) {
  112. util::fail('名称已经存在了');
  113. }
  114. }
  115. }
  116. if (!empty($mobile)) {
  117. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  118. if (!empty($has)) {
  119. $connection = Yii::$app->db;
  120. $transaction = $connection->beginTransaction();
  121. try {
  122. $shopId = $this->shopId;
  123. $currentShopId = $has['shopId'] ?? 0;
  124. if (empty($currentShopId)) {
  125. util::fail('添加失败');
  126. }
  127. $hasGhs = GhsClass::getByCondition(['ownShopId' => $this->shopId, 'shopId' => $currentShopId], true);
  128. if (!empty($hasGhs)) {
  129. $name = $hasGhs->name ?? '';
  130. util::fail("手机已添加过了,供货商名称:【{$name}】");
  131. }
  132. $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
  133. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  134. $transaction->commit();
  135. util::success($ghs);
  136. } catch (\Exception $exception) {
  137. $transaction->rollBack();
  138. Yii::info("添加供货商没有成功:" . $exception->getMessage());
  139. util::fail('添加供货商没有成功');
  140. }
  141. util::fail('添加失败,请联系管理员');
  142. }
  143. }
  144. $connection = Yii::$app->db;
  145. $transaction = $connection->beginTransaction();
  146. try {
  147. if (empty($mobile)) {
  148. //获取虚拟手机号
  149. $mobile = orderSn::getMobileSn();
  150. }
  151. $sjId = $this->sjId;
  152. $shopId = $this->shopId;
  153. $sjName = $this->sj->name ?? '';
  154. $address = $post['address'] ?? '';
  155. $applyData = [
  156. 'name' => $name,
  157. 'licenseNo' => $mobile,
  158. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  159. 'mobile' => $mobile,
  160. 'introSjId' => $sjId,
  161. 'introSjName' => $sjName,
  162. 'introShopId' => $shopId,
  163. 'introStyle' => SjClass::STYLE_SUPPLIER,
  164. 'from' => ApplyClass::FROM_GHS,
  165. 'style' => dict::getDict('ptStyle', 'kmGhs'),
  166. 'address' => $address,
  167. 'status' => ApplyClass::STATUS_PASS,
  168. ];
  169. $apply = ApplyService::replaceKmGhs($applyData);
  170. $id = $apply['id'] ?? 0;
  171. $respond = \bizJd\apply\services\ApplyService::pass($id);
  172. $shop = $respond['shop'] ?? [];
  173. $sj = $respond['sj'] ?? [];
  174. $currentSjId = $sj['id'] ?? 0;
  175. $currentShopId = $shop->id ?? 0;
  176. ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]);
  177. if (empty($currentShopId)) {
  178. util::fail('供货商没有添加成功!');
  179. }
  180. $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
  181. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  182. if (is_numeric($location)) {
  183. //本地批发商的标记
  184. $ghsId = $ghs['id'] ?? 0;
  185. \biz\ghs\classes\GhsClass::updateById($ghsId, ['location' => $location]);
  186. }
  187. $transaction->commit();
  188. util::success($ghs);
  189. } catch (\Exception $exception) {
  190. $transaction->rollBack();
  191. Yii::info("添加供货商没有成功:" . $exception->getMessage());
  192. util::fail('添加供货商没有成功');
  193. }
  194. }
  195. //供货商列表 ssh 2021.1.18
  196. public function actionList()
  197. {
  198. $get = Yii::$app->request->get();
  199. $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
  200. $delStatus = isset($get['delStatus']) && is_numeric($get['delStatus']) ? (int)$get['delStatus'] : 0;
  201. $where = [
  202. 'ownShopId' => $this->shopId,
  203. 'delStatus' => $delStatus,
  204. ];
  205. $sortType = $get['sortType'] ?? 'all';
  206. if (!in_array($sortType, ['all', 'debt', 'expend'], true)) {
  207. $sortType = 'all';
  208. }
  209. if (!empty($name)) {
  210. if (stringUtil::isLetter($name)) {
  211. $where['py'] = ['like', $name];
  212. } else {
  213. $where['name'] = ['like', $name];
  214. }
  215. }
  216. $location = $get['location'] ?? '';
  217. if (is_numeric($location)) {
  218. $where['location'] = $location;
  219. }
  220. //采购限制访问,有多处要同步修改,权限管理问题,关键词cg_limit_access
  221. if (getenv('YII_ENV') == 'production') {
  222. //纯彩花艺
  223. if ($this->mainId == 10) {
  224. if (!in_array($this->adminId, [37, 988, 14346])) {
  225. util::fail('没有数据哦,编号129');
  226. }
  227. }
  228. //天天鲜花十堰店
  229. if ($this->mainId == 7184) {
  230. if (!in_array($this->adminId, [8340, 8345, 9433])) {
  231. util::fail('没有数据哦,编号23');
  232. }
  233. }
  234. //小向花卉采购控制
  235. if ($this->mainId == 23390) {
  236. if (!in_array($this->adminId, [24586, 24115, 24759, 26390, 23960, 25011, 25004, 24655, 28521, 4, 24043, 77951])) {
  237. util::fail('没有数据哦,编号35');
  238. }
  239. }
  240. //贴心鲜花批发,只有老板可以查看
  241. if ($this->mainId == 15144) {
  242. if (!in_array($this->adminId, [16163])) {
  243. util::fail('暂时无法查看哦,编号6868');
  244. }
  245. }
  246. //捷芳鲜花批发,限制不能查看采购权限的人
  247. if ($this->mainId == 45354) {
  248. if (in_array($this->adminId, [47094, 47130])) {
  249. util::fail('暂时无法查看哦,编号6811');
  250. }
  251. }
  252. }
  253. $list = GhsClass::getGhsList($where, $sortType);
  254. $page = isset($get['page']) ? (int)$get['page'] : 1;
  255. if ($page <= 1) {
  256. $list['tabCounts'] = GhsClass::getSupplierTabCounts($this->shopId);
  257. }
  258. $staff = $this->shopAdmin;
  259. $totalDebtNum = 0;
  260. if (!isset($staff->finance) || $staff->finance == 0) {
  261. $totalDebtAmount = 0;
  262. //没有财务权限的人不让看到欠款多少
  263. if (!empty($list['list'])) {
  264. foreach ($list['list'] as $key => $val) {
  265. $list['list'][$key]['debtAmount'] = 0;
  266. $list['list'][$key]['debtNum'] = 0;
  267. $list['list'][$key]['remainDebtAmount'] = '0.00';
  268. // 净余额协议下待结体现在负 balance,无财务权限时一并隐藏
  269. if (bccomp($list['list'][$key]['balance'] ?? '0', '0', 2) < 0) {
  270. $list['list'][$key]['balance'] = '0.00';
  271. $list['list'][$key]['displayBalance'] = '0.00';
  272. }
  273. }
  274. }
  275. } else {
  276. // 总待结:一次汇总全店待结金额与笔数
  277. $debtStats = GhsClass::sumTotalOutstandingDebtStats($this->shopId, 0);
  278. $totalDebtAmount = $debtStats['amount'];
  279. $totalDebtNum = $debtStats['num'];
  280. }
  281. $list['totalDebtAmount'] = $totalDebtAmount;
  282. $list['totalDebtNum'] = $totalDebtNum;
  283. util::success($list);
  284. }
  285. //下载供货商 ssh 20240506
  286. public function actionDownloadGhs()
  287. {
  288. //$get = Yii::$app->request->get();
  289. $mainId = $this->mainId;
  290. $respond = GhsClass::getGhsFile($mainId);
  291. $file = $respond['file'] ?? '';
  292. $shortFile = $respond['shortFile'] ?? '';
  293. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  294. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  295. }
  296. }