MerchantIntentionRepository.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace app\common\repositories\system\merchant;
  3. use app\common\repositories\BaseRepository;
  4. use ln\jobs\SendSmsJob;
  5. use FormBuilder\Factory\Elm;
  6. use app\common\dao\system\merchant\MerchantIntentionDao;
  7. use think\exception\ValidateException;
  8. use think\facade\Db;
  9. use think\facade\Queue;
  10. use think\facade\Route;
  11. /**
  12. * @mixin MerchantIntentionDao
  13. */
  14. class MerchantIntentionRepository extends BaseRepository
  15. {
  16. public function __construct(MerchantIntentionDao $dao)
  17. {
  18. $this->dao = $dao;
  19. }
  20. public function getList(array $where, $page, $limit)
  21. {
  22. $query = $this->dao->search($where);
  23. $count = $query->count();
  24. $list = $query->page($page, $limit)->order('create_time DESC , status ASC')->with(['merchantCategory', 'merchantType'])->select();
  25. return compact('count', 'list');
  26. }
  27. public function detail($id, ?int $uid)
  28. {
  29. $where = ['mer_intention_id' => $id];
  30. if (!is_null($uid)) {
  31. $where['uid'] = $uid;
  32. }
  33. return $this->dao->search($where)->find();
  34. }
  35. public function updateIntention($id, array $data)
  36. {
  37. if ($this->dao->existsWhere(['mer_intention_id' => $id, 'status' => '1']))
  38. throw new ValidateException('当前状态不能修改');
  39. $data['images'] = implode(',', (array)$data['images']);
  40. $data['status'] = 0;
  41. $data['fail_msg'] = '';
  42. return $this->dao->update($id, $data);
  43. }
  44. public function markForm($id)
  45. {
  46. $data = $this->dao->get($id);
  47. $form = Elm::createForm(Route::buildUrl('systemMerchantIntentionMark', ['id' => $id])->build());
  48. $form->setRule([
  49. Elm::textarea('mark', '备注', $data['remark'])->required(),
  50. ]);
  51. return $form->setTitle('修改备注');
  52. }
  53. public function statusForm($id)
  54. {
  55. $form = Elm::createForm(Route::buildUrl('systemMerchantIntentionStatus', ['id' => $id])->build());
  56. $form->setRule([
  57. Elm::select('status', '审核状态', 1)->options([
  58. ['value' => 1, 'label' => '同意'],
  59. ['value' => 2, 'label' => '拒绝'],
  60. ])->control([
  61. [
  62. 'value' => 1,
  63. 'rule' => [
  64. Elm::radio('create_mer', '自动创建商户', 1)->options([
  65. ['value' => 1, 'label' => '创建'],
  66. ['value' => 2, 'label' => '不创建'],
  67. ])
  68. ]
  69. ],
  70. [
  71. 'value' => 2,
  72. 'rule' => [
  73. Elm::textarea('fail_msg', '失败原因', '信息填写有误')
  74. ]
  75. ]
  76. ]),
  77. ]);
  78. return $form->setTitle('修改审核状态');
  79. }
  80. public function updateStatus($id, $data)
  81. {
  82. $create = $data['create_mer'] == 1;
  83. unset($data['create_mer']);
  84. $intention = $this->search(['mer_intention_id' => $id])->find();
  85. if (!$intention)
  86. throw new ValidateException('信息不存在');
  87. if ($intention->status)
  88. throw new ValidateException('状态有误,修改失败');
  89. $config = systemConfig(['broadcast_room_type', 'broadcast_goods_type']);
  90. Db::transaction(function () use ($config, $intention, $data, $create) {
  91. if ($data['status'] == 1) {
  92. $data['fail_mag'] = '';
  93. if ($create) {
  94. $password = substr(md5(time() . $intention['phone']), 0, 8);
  95. $merchant = app()->make(MerchantRepository::class)->createMerchant([
  96. 'mer_name' => $intention['mer_name'],
  97. 'mer_phone' => $intention['phone'],
  98. 'mer_account' => $intention['phone'],
  99. 'category_id' => $intention['merchant_category_id'],
  100. 'type_id' => $intention['mer_type_id'],
  101. 'real_name' => $intention['name'],
  102. 'status' => 1,
  103. 'is_audit' => 1,
  104. 'is_bro_room' => $config['broadcast_room_type'] == 1 ? 0 : 1,
  105. 'is_bro_goods' => $config['broadcast_goods_type'] == 1 ? 0 : 1,
  106. 'mer_password' => $password
  107. ]);
  108. $data['mer_id'] = $merchant->mer_id;
  109. Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_SUCCESS', 'id' => [
  110. 'mer' => $intention['mer_name'], 'date' => $intention->create_time, 'pwd' => $password, 'phone' => $intention['phone']
  111. ]]);
  112. }
  113. } else {
  114. Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_FAIL', 'id' => [
  115. 'mer' => $intention['mer_name'], 'date' => $intention->create_time, 'phone' => $intention['phone']
  116. ]]);
  117. }
  118. $intention->save($data);
  119. });
  120. }
  121. }