GhsController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\sj\classes\SjClass;
  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\stringUtil;
  10. use Yii;
  11. use common\components\util;
  12. class GhsController extends BaseController
  13. {
  14. //添加供货商 ssh 20210611
  15. public function actionAdd()
  16. {
  17. $post = Yii::$app->request->post();
  18. $mobile = $post['mobile'] ?? '';
  19. $confirmMobile = $post['confirmMobile'];
  20. if (stringUtil::isMobile($mobile) == false) {
  21. util::fail(' 请填写正确的手机号');
  22. }
  23. if ($mobile != $confirmMobile) {
  24. util::fail('二次号码填写不一致');
  25. }
  26. $name = $post['name'] ?? '';
  27. if (empty($name)) {
  28. util::fail('名称不能为空');
  29. }
  30. if (stringUtil::getWordNum($name) > 8) {
  31. util::fail('名称不能超过8个汉字');
  32. }
  33. $has = ApplyClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  34. if (!empty($has)) {
  35. util::fail('名称已经存在');
  36. }
  37. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  38. if (!empty($has)) {
  39. $connection = Yii::$app->db;
  40. $transaction = $connection->beginTransaction();
  41. try {
  42. $shopId = $this->shopId;
  43. $currentShopId = $has['shopId'] ?? 0;
  44. if (empty($currentShopId)) {
  45. util::fail('添加失败');
  46. }
  47. $hasGhs = GhsClass::getByCondition(['ownShopId' => $this->shopId, 'shopId' => $currentShopId], true);
  48. if (!empty($hasGhs)) {
  49. $name = $hasGhs->name ?? '';
  50. util::fail("手机已添加过了,供货商名称:【{$name}】");
  51. }
  52. $ghs = GhsClass::build($currentShopId, $shopId, 1);
  53. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  54. $transaction->commit();
  55. util::success($ghs);
  56. } catch (\Exception $exception) {
  57. $transaction->rollBack();
  58. Yii::info("添加供货商没有成功:" . $exception->getMessage());
  59. util::fail('添加供货商没有成功');
  60. }
  61. util::fail('添加失败,请联系管理员');
  62. }
  63. $connection = Yii::$app->db;
  64. $transaction = $connection->beginTransaction();
  65. try {
  66. $sjId = $this->sjId;
  67. $shopId = $this->shopId;
  68. $sjName = $this->sj->name ?? '';
  69. $address = $post['address'] ?? '';
  70. $applyData = [
  71. 'name' => $name,
  72. 'licenseNo' => $mobile,
  73. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  74. 'mobile' => $mobile,
  75. 'introSjId' => $sjId,
  76. 'introSjName' => $sjName,
  77. 'introShopId' => $shopId,
  78. 'introStyle' => SjClass::STYLE_SUPPLIER,
  79. 'from' => ApplyClass::FROM_GHS,
  80. 'style' => dict::getDict('ptStyle', 'kmGhs'),
  81. 'address' => $address,
  82. 'status' => ApplyClass::STATUS_PASS,
  83. ];
  84. $apply = ApplyService::replaceKmGhs($applyData);
  85. $id = $apply['id'] ?? 0;
  86. $respond = \bizJd\apply\services\ApplyService::pass($id);
  87. $shop = $respond['shop'] ?? [];
  88. $sj = $respond['sj'] ?? [];
  89. $currentSjId = $sj['id'] ?? 0;
  90. $currentShopId = $shop->id ?? 0;
  91. ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]);
  92. if (empty($currentShopId)) {
  93. util::fail('供货商没有添加成功!');
  94. }
  95. $ghs = GhsClass::build($currentShopId, $shopId, 1);
  96. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  97. $transaction->commit();
  98. util::success($ghs);
  99. } catch (\Exception $exception) {
  100. $transaction->rollBack();
  101. Yii::info("添加供货商没有成功:" . $exception->getMessage());
  102. util::fail('添加供货商没有成功');
  103. }
  104. }
  105. //供货商列表 ssh 2021.1.18
  106. public function actionList()
  107. {
  108. $get = Yii::$app->request->get();
  109. $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
  110. $where = ['ownShopId' => $this->shopId];
  111. if (!empty($name)) {
  112. if (stringUtil::isLetter($name)) {
  113. $where['py'] = ['like', $name];
  114. } else {
  115. $where['name'] = ['like', $name];
  116. }
  117. }
  118. $list = GhsClass::getGhsList($where);
  119. util::success($list);
  120. }
  121. }