GhsController.php 10 KB

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