GhsController.php 3.7 KB

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