GhsController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. //添加供应商 shish 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. 'replace' => 1,//1表示供应商添加的客户或供应商
  84. ];
  85. $apply = ApplyService::replaceKmGhs($applyData);
  86. $id = $apply['id'] ?? 0;
  87. $respond = ApplyService::pass($id);
  88. $shop = $respond['shop'] ?? [];
  89. $sj = $respond['sj'] ?? [];
  90. $currentSjId = $sj['id'] ?? 0;
  91. $currentShopId = $shop->id ?? 0;
  92. ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]);
  93. if (empty($currentShopId)) {
  94. util::fail('供应商没有添加成功!');
  95. }
  96. $ghs = GhsClass::build($currentShopId, $shopId, 1);
  97. $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
  98. $transaction->commit();
  99. util::success($ghs);
  100. } catch (\Exception $exception) {
  101. $transaction->rollBack();
  102. Yii::info("添加供应商没有成功:" . $exception->getMessage());
  103. util::fail('添加供应商没有成功');
  104. }
  105. }
  106. //供应商列表 ssh 2021.1.18
  107. public function actionList()
  108. {
  109. $get = Yii::$app->request->get();
  110. $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
  111. $where = ['ownShopId' => $this->shopId];
  112. if (!empty($name)) {
  113. if (stringUtil::isLetter($name)) {
  114. $where['py'] = ['like', $name];
  115. } else {
  116. $where['name'] = ['like', $name];
  117. }
  118. }
  119. $list = GhsClass::getGhsList($where);
  120. util::success($list);
  121. }
  122. }