GhsController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. //添加供货商 ssh 20210611
  74. public function actionAdd()
  75. {
  76. $post = Yii::$app->request->post();
  77. $location = $post['location'] ?? '';
  78. $mobile = $post['mobile'] ?? '';
  79. $name = $post['name'] ?? '';
  80. if (empty($name)) {
  81. util::fail('名称不能为空');
  82. }
  83. if (stringUtil::getWordNum($name) > 27) {
  84. util::fail('名称不能超过27个汉字');
  85. }
  86. $hasGhsList = GhsClass::getAllByCondition(['ownShopId' => $this->shopId], null, '*', null, true);
  87. if (!empty($hasGhsList)) {
  88. foreach ($hasGhsList as $hasGhs) {
  89. $hasGhsName = $hasGhs->name ?? '';
  90. if ($hasGhsName == $name) {
  91. util::fail('名称已经存在了');
  92. }
  93. }
  94. }
  95. if (!empty($mobile)) {
  96. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  97. if (!empty($has)) {
  98. $connection = Yii::$app->db;
  99. $transaction = $connection->beginTransaction();
  100. try {
  101. $shopId = $this->shopId;
  102. $currentShopId = $has['shopId'] ?? 0;
  103. if (empty($currentShopId)) {
  104. util::fail('添加失败');
  105. }
  106. $hasGhs = GhsClass::getByCondition(['ownShopId' => $this->shopId, 'shopId' => $currentShopId], true);
  107. if (!empty($hasGhs)) {
  108. $name = $hasGhs->name ?? '';
  109. util::fail("手机已添加过了,供货商名称:【{$name}】");
  110. }
  111. $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
  112. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  113. $transaction->commit();
  114. util::success($ghs);
  115. } catch (\Exception $exception) {
  116. $transaction->rollBack();
  117. Yii::info("添加供货商没有成功:" . $exception->getMessage());
  118. util::fail('添加供货商没有成功');
  119. }
  120. util::fail('添加失败,请联系管理员');
  121. }
  122. }
  123. $connection = Yii::$app->db;
  124. $transaction = $connection->beginTransaction();
  125. try {
  126. if (empty($mobile)) {
  127. //获取虚拟手机号
  128. $mobile = orderSn::getMobileSn();
  129. }
  130. $sjId = $this->sjId;
  131. $shopId = $this->shopId;
  132. $sjName = $this->sj->name ?? '';
  133. $address = $post['address'] ?? '';
  134. $applyData = [
  135. 'name' => $name,
  136. 'licenseNo' => $mobile,
  137. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  138. 'mobile' => $mobile,
  139. 'introSjId' => $sjId,
  140. 'introSjName' => $sjName,
  141. 'introShopId' => $shopId,
  142. 'introStyle' => SjClass::STYLE_SUPPLIER,
  143. 'from' => ApplyClass::FROM_GHS,
  144. 'style' => dict::getDict('ptStyle', 'kmGhs'),
  145. 'address' => $address,
  146. 'status' => ApplyClass::STATUS_PASS,
  147. ];
  148. $apply = ApplyService::replaceKmGhs($applyData);
  149. $id = $apply['id'] ?? 0;
  150. $respond = \bizJd\apply\services\ApplyService::pass($id);
  151. $shop = $respond['shop'] ?? [];
  152. $sj = $respond['sj'] ?? [];
  153. $currentSjId = $sj['id'] ?? 0;
  154. $currentShopId = $shop->id ?? 0;
  155. ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]);
  156. if (empty($currentShopId)) {
  157. util::fail('供货商没有添加成功!');
  158. }
  159. $ghs = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1);
  160. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  161. if (is_numeric($location)) {
  162. //本地批发商的标记
  163. $ghsId = $ghs['id'] ?? 0;
  164. \biz\ghs\classes\GhsClass::updateById($ghsId, ['location' => $location]);
  165. }
  166. $transaction->commit();
  167. util::success($ghs);
  168. } catch (\Exception $exception) {
  169. $transaction->rollBack();
  170. Yii::info("添加供货商没有成功:" . $exception->getMessage());
  171. util::fail('添加供货商没有成功');
  172. }
  173. }
  174. //供货商列表 ssh 2021.1.18
  175. public function actionList()
  176. {
  177. $get = Yii::$app->request->get();
  178. $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
  179. $delStatus = isset($get['delStatus']) && is_numeric($get['delStatus']) ? (int)$get['delStatus'] : 0;
  180. $where = [
  181. 'ownShopId' => $this->shopId,
  182. 'delStatus' => $delStatus,
  183. ];
  184. $sortType = $get['sortType'] ?? 'all';
  185. if (!in_array($sortType, ['all', 'debt', 'expend'], true)) {
  186. $sortType = 'all';
  187. }
  188. if (!empty($name)) {
  189. if (stringUtil::isLetter($name)) {
  190. $where['py'] = ['like', $name];
  191. } else {
  192. $where['name'] = ['like', $name];
  193. }
  194. }
  195. $location = $get['location'] ?? '';
  196. if (is_numeric($location)) {
  197. $where['location'] = $location;
  198. }
  199. //采购限制访问,有多处要同步修改,权限管理问题,关键词cg_limit_access
  200. if (getenv('YII_ENV') == 'production') {
  201. //纯彩花艺
  202. if ($this->mainId == 10) {
  203. if (!in_array($this->adminId, [37, 988, 14346])) {
  204. util::fail('没有数据哦,编号129');
  205. }
  206. }
  207. //天天鲜花十堰店
  208. if ($this->mainId == 7184) {
  209. if (!in_array($this->adminId, [8340, 8345, 9433])) {
  210. util::fail('没有数据哦,编号23');
  211. }
  212. }
  213. //小向花卉采购控制
  214. if ($this->mainId == 23390) {
  215. if (!in_array($this->adminId, [24586, 24115, 24759, 26390, 23960, 25011, 25004, 24655, 28521, 4, 24043, 77951])) {
  216. util::fail('没有数据哦,编号35');
  217. }
  218. }
  219. //贴心鲜花批发,只有老板可以查看
  220. if ($this->mainId == 15144) {
  221. if (!in_array($this->adminId, [16163])) {
  222. util::fail('暂时无法查看哦,编号6868');
  223. }
  224. }
  225. //捷芳鲜花批发,限制不能查看采购权限的人
  226. if ($this->mainId == 45354) {
  227. if (in_array($this->adminId, [47094, 47130])) {
  228. util::fail('暂时无法查看哦,编号6811');
  229. }
  230. }
  231. }
  232. $list = GhsClass::getGhsList($where, $sortType);
  233. $page = isset($get['page']) ? (int)$get['page'] : 1;
  234. if ($page <= 1) {
  235. $list['tabCounts'] = GhsClass::getSupplierTabCounts($this->shopId);
  236. }
  237. $staff = $this->shopAdmin;
  238. $totalDebtNum = 0;
  239. if (!isset($staff->finance) || $staff->finance == 0) {
  240. $totalDebtAmount = 0;
  241. //没有财务权限的人不让看到欠款多少
  242. if (!empty($list['list'])) {
  243. foreach ($list['list'] as $key => $val) {
  244. $list['list'][$key]['debtAmount'] = 0;
  245. $list['list'][$key]['debtNum'] = 0;
  246. $list['list'][$key]['remainDebtAmount'] = '0.00';
  247. // 净余额协议下待结体现在负 balance,无财务权限时一并隐藏
  248. if (bccomp($list['list'][$key]['balance'] ?? '0', '0', 2) < 0) {
  249. $list['list'][$key]['balance'] = '0.00';
  250. $list['list'][$key]['displayBalance'] = '0.00';
  251. }
  252. }
  253. }
  254. } else {
  255. // 总待结:一次汇总全店待结金额与笔数
  256. $debtStats = GhsClass::sumTotalOutstandingDebtStats($this->shopId, 0);
  257. $totalDebtAmount = $debtStats['amount'];
  258. $totalDebtNum = $debtStats['num'];
  259. }
  260. $list['totalDebtAmount'] = $totalDebtAmount;
  261. $list['totalDebtNum'] = $totalDebtNum;
  262. util::success($list);
  263. }
  264. //下载供货商 ssh 20240506
  265. public function actionDownloadGhs()
  266. {
  267. //$get = Yii::$app->request->get();
  268. $mainId = $this->mainId;
  269. $respond = GhsClass::getGhsFile($mainId);
  270. $file = $respond['file'] ?? '';
  271. $shortFile = $respond['shortFile'] ?? '';
  272. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  273. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  274. }
  275. }