SjController.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace pt\controllers;
  3. use biz\sj\classes\SjClass;
  4. use common\components\util;
  5. use biz\sj\services\MerchantService;
  6. use Yii;
  7. class SjController extends BaseController
  8. {
  9. //新增商家 shish 2021.3.29
  10. public function actionAdd()
  11. {
  12. $get = Yii::$app->request->get();
  13. $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
  14. if (empty($name)) {
  15. util::fail('请填写名称');
  16. }
  17. $connection = Yii::$app->db;
  18. $transaction = $connection->beginTransaction();
  19. try {
  20. $apply['name'] = $name;
  21. $apply['style'] = SjClass::STYLE_KM_SUPPLIER;
  22. $has = SjClass::getByCondition(['name' => $name]);
  23. if (!empty($has)) {
  24. util::fail('名称已经存在');
  25. }
  26. MerchantService::initSjInfo($apply);
  27. $transaction->commit();
  28. util::complete();
  29. } catch (\Exception $exception) {
  30. Yii::info("添加商家失败:" . $exception->getMessage());
  31. util::fail('操作失败');
  32. }
  33. }
  34. //商家列表 ssh 2019.12.20
  35. public function actionList()
  36. {
  37. $get = Yii::$app->request->get();
  38. $where = ['delStatus' => 0];
  39. if (isset($get['name']) && !empty($get['name'])) {
  40. $where['name'] = ['like', $get['name']];
  41. }
  42. $list = MerchantService::getMerchantList($where);
  43. util::success($list);
  44. }
  45. }