ApplicationForm.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. namespace App\Models\Api\Promoter;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\DB;
  6. use App\Models\Api\Promoter\Configuration as ConfigurationModel;
  7. use App\Models\Api\Promoter\Users as UsersModel;
  8. /**
  9. * 推广员申请表模型
  10. * @author 唐远望
  11. * @version 1.0
  12. * @date 2025-09-04
  13. */
  14. class ApplicationForm extends Model
  15. {
  16. use HasFactory;
  17. // 与模型关联的表名
  18. protected $table = 'promoter_application_form';
  19. // 是否主动维护时间戳
  20. public $timestamps = false;
  21. protected $connection = 'company';
  22. // 定义时间戳字段名
  23. // const CREATED_AT = 'insert_time';
  24. // const UPDATED_AT = 'update_time';
  25. /**
  26. * 添加
  27. * @author 唐远望
  28. * @version 1.0
  29. * @date 2025-05-27
  30. */
  31. public function addApplicationForm_content($data)
  32. {
  33. $insert_data = [
  34. 'company_id' => $data['company_id'],
  35. 'superior_custom_uid' => $data['superior_custom_uid'],
  36. 'custom_uid' => $data['custom_uid'],
  37. 'full_name' => $data['full_name'],
  38. 'mobile_phone' => $data['mobile_phone'],
  39. 'email' => $data['email'],
  40. 'city' => $data['city'],
  41. 'company_name' => $data['company_name'],
  42. 'other_parameters' => json_encode($data['other_parameters']),
  43. 'insert_time' => time(),
  44. 'status' => $data['status'],
  45. 'audit_remark' => $this->isNeedAudit($data['company_id']) ? '' : '',
  46. ];
  47. $ApplicationForm_id = $this->insertGetId($insert_data);
  48. return $ApplicationForm_id;
  49. }
  50. /**
  51. * 是否需要审核
  52. * @author 唐远望
  53. * @version 1.0
  54. * @date 2025-09-05
  55. */
  56. public function isNeedAudit($company_id)
  57. {
  58. $is_need_audit = true; //默认需要审核
  59. $ConfigurationModel = new ConfigurationModel();
  60. //获取推广员申请条件
  61. $application_requirements_data = $ConfigurationModel->where(['code_name' => 'application_requirements', 'company_id' => $company_id])->first();
  62. if (!$application_requirements_data) {
  63. return $is_need_audit;
  64. }
  65. $application_requirements_content_data = $application_requirements_data->content;
  66. if ($application_requirements_content_data['is_review'] == 0) {
  67. $is_need_audit = false;//不需要审核
  68. }
  69. return $is_need_audit;
  70. }
  71. /**
  72. * 写入数据
  73. * @author 唐远望
  74. * @version 1.0
  75. * @date 2025-05-27
  76. * @param $data
  77. * @return bool
  78. */
  79. public function addApplicationForm($data)
  80. {
  81. DB::beginTransaction();
  82. try {
  83. $status = $this->isNeedAudit($data['company_id']) ? 1 : 2;
  84. $data['status'] = $status;
  85. $insert_data = [
  86. 'company_id' => $data['company_id'],
  87. 'superior_custom_uid' => $data['superior_custom_uid'],
  88. 'custom_uid' => $data['custom_uid'],
  89. 'full_name' => $data['full_name'],
  90. 'mobile_phone' => $data['mobile_phone'],
  91. 'email' => isset($data['email'])?$data['email']:'',
  92. 'city' => isset($data['city'])?$data['city']:'',
  93. 'company_name' => isset($data['company_name'])?$data['company_name']:'',
  94. 'other_parameters' => json_encode($data['other_parameters']),
  95. 'insert_time' => time(),
  96. 'status' => $data['status'],
  97. 'audit_remark' => $this->isNeedAudit($data['company_id']) ? '' : '',
  98. ];
  99. $ApplicationForm_id = $this->insertGetId($insert_data);
  100. if ($status == 2) { //审核状态1=待审核,2=审核通过,3=审核拒绝
  101. $insert_data = [
  102. 'company_id' => $data['company_id'],
  103. 'superior_custom_uid' => $data['superior_custom_uid'],
  104. 'custom_uid' => $data['custom_uid'],
  105. 'full_name' => $data['full_name'],
  106. 'mobile_phone' => $data['mobile_phone'],
  107. 'email' => isset($data['email'])?$data['email']:'',
  108. 'city' => isset($data['city'])?$data['city']:'',
  109. 'company_name' => isset($data['company_name'])?$data['company_name']:'',
  110. 'other_parameters' => json_encode($data['other_parameters']),
  111. 'insert_time' => time(),
  112. 'promoter_remark' => '',
  113. 'status' => '1'
  114. ];
  115. (new UsersModel())->insertGetId($insert_data);
  116. }
  117. DB::commit();
  118. return $ApplicationForm_id;
  119. // 成功处理...
  120. } catch (\Exception $e) {
  121. DB::rollBack();
  122. // 错误处理...
  123. return ['code' => 'error', 'msg' => $e->getMessage()];
  124. }
  125. }
  126. /**
  127. * 编辑内容
  128. * @author 唐远望
  129. * @version 1.0
  130. * @date 2025-05-27
  131. * @param $data
  132. * @return bool
  133. */
  134. public function editApplicationForm_content($where, $data)
  135. {
  136. $ApplicationForm = $this->where($where)->first();
  137. if (!$ApplicationForm) {
  138. return false;
  139. }
  140. $ApplicationForm->full_name = $data['full_name'];
  141. $ApplicationForm->mobile_phone = $data['mobile_phone'];
  142. $ApplicationForm->email = $data['email'];
  143. $ApplicationForm->city = $data['city'];
  144. $ApplicationForm->company_name = $data['company_name'];
  145. $ApplicationForm->other_parameters = json_encode($data['other_parameters']);
  146. $ApplicationForm->update_time = time();
  147. $ApplicationForm->save();
  148. return true;
  149. }
  150. /**
  151. * 更新数据
  152. * @author 唐远望
  153. * @version 1.0
  154. * @date 2025-05-27
  155. * @param $data
  156. * @return bool
  157. */
  158. public function updateApplicationForm($where, $data)
  159. {
  160. DB::beginTransaction();
  161. try {
  162. $this->editApplicationForm_content($where, $data);
  163. DB::commit();
  164. return true;
  165. // 成功处理...
  166. } catch (\Exception $e) {
  167. DB::rollBack();
  168. // 错误处理...
  169. return false;
  170. }
  171. }
  172. /**
  173. * 修改状态
  174. * @author 唐远望
  175. * @version 1.0
  176. * @date 2025-05-27
  177. * @param $id
  178. * @param $status
  179. * @return bool
  180. */
  181. public function changeStatus($where, $status)
  182. {
  183. $ApplicationForm = $this->where($where)->first();
  184. if (!$ApplicationForm) {
  185. return false;
  186. }
  187. $ApplicationForm->status = $status;
  188. $ApplicationForm->update_time = time();
  189. $ApplicationForm->save();
  190. return true;
  191. }
  192. /**
  193. * 删除数据
  194. * @author 唐远望
  195. * @version 1.0
  196. * @date 2025-05-27
  197. * @param $id
  198. * @return bool
  199. */
  200. public function deleteApplicationForm($where)
  201. {
  202. $ApplicationForm = $this->where($where)->first();
  203. if (!$ApplicationForm) {
  204. return false;
  205. }
  206. $ApplicationForm->delete();
  207. return true;
  208. }
  209. }