NumberSequence.php 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\crm\model;
  3. use think\Db;
  4. use app\admin\model\Common;
  5. use think\Request;
  6. use think\Validate;
  7. class NumberSequence extends Common
  8. {
  9. /**
  10. * 为了数据库的整洁,同时又不影响Model和Controller的名称
  11. * 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀
  12. */
  13. protected $name = 'crm_number_sequence';
  14. /**
  15. *自定义回访编号(创建)
  16. * @return
  17. */
  18. public function createData($param)
  19. {
  20. $user_id = $param['user_id'];
  21. $param['sort']+=1;
  22. if ($data = $this->data($param)->allowField(true)->isUpdate(false)->save()) {
  23. //修改记录
  24. updateActionLog($user_id, 'crm_number_sequence', $this->number_sequence_id, '', '', '创建了自动生成编号规则');
  25. return $data;
  26. } else {
  27. $this->error = '添加失败';
  28. return false;
  29. }
  30. }
  31. /**
  32. * 列表
  33. * @param $param
  34. * @return array
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. * @throws \think\exception\DbException
  38. */
  39. public function getDataList($param)
  40. {
  41. $list = db('crm_number_sequence')
  42. ->field('number_type,number_sequence_id,status')
  43. ->group('number_type')
  44. ->select();
  45. $data = array();
  46. foreach ($list as $key => $v) {
  47. $data[]['setting'] = db('crm_number_sequence')
  48. ->where('number_type', $v['number_type'])
  49. ->order('sort asc')
  50. ->select();
  51. $data[$key]['number_type'] = $v['number_type'];
  52. $data[$key]['number_sequence_id'] = $v['number_sequence_id'];
  53. # 前端的status值为1代表启用,后端保存的status值为0代表启用,这里执行以下取反操作;
  54. $data[$key]['status'] = $v['status'] == 0 ? 1 : 0;
  55. }
  56. return $data;
  57. }
  58. /**
  59. * @param $param
  60. * @param string $param_id
  61. * @return array|false
  62. */
  63. public function numberSequenceUpdate($param,$param_id=''){
  64. $user_id = $param['user_id'];
  65. if ($this->update($param, ['number_sequence_id' => $param_id], true)) {
  66. //修改记录
  67. updateActionLog($user_id, 'crm_number_sequence', $param_id, '', $param);
  68. $data = [];
  69. $data['number_sequence_id'] = $param_id;
  70. return $data;
  71. } else {
  72. $this->error = '编辑失败';
  73. return false;
  74. }
  75. }
  76. /**
  77. * 批量更新上次生成的编号【last_date】、上次生成的时间【create_time】
  78. *
  79. * @param $data
  80. * @return array|false|\think\Collection|\think\model\Collection
  81. * @throws \Exception
  82. */
  83. public function batchUpdate($data)
  84. {
  85. return $this->saveAll($data);
  86. }
  87. }