ConfigData.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 客户设置
  4. // +----------------------------------------------------------------------
  5. // | Author: Michael_xu | gengxiaoxu@5kcrm.com
  6. // +----------------------------------------------------------------------
  7. namespace app\crm\model;
  8. use think\Db;
  9. use app\admin\model\Common;
  10. use think\Request;
  11. use think\Validate;
  12. class ConfigData extends Common
  13. {
  14. /**
  15. * 为了数据库的整洁,同时又不影响Model和Controller的名称
  16. * 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀
  17. */
  18. protected $name = 'crm_config';
  19. protected $createTime = 'create_time';
  20. protected $updateTime = 'update_time';
  21. protected $autoWriteTimestamp = true;
  22. /**
  23. * 保存相关信息
  24. * @author Michael_xu
  25. * @param
  26. * @return
  27. */
  28. public function createData($param)
  29. {
  30. $data = [];
  31. $config = $param['config'] ? 1 : 0;
  32. $remind_config = $param['remind_config'] ? 1 : 0;
  33. //启用
  34. if ($config == 1) {
  35. $follow_day = $param['follow_day'] ? : 0;
  36. $resFollow = db('crm_config')->where(['name' => 'follow_day'])->update(['value' => $follow_day]);
  37. $deal_day = $param['deal_day'] ? : 0;
  38. $resDeal = db('crm_config')->where(['name' => 'deal_day'])->update(['value' => $deal_day]);
  39. }
  40. $resConfig = db('crm_config')->where(['name' => 'config'])->update(['value' => $config]);
  41. if ($remind_config == 1) {
  42. $remind_day = $param['remind_day'] ? : 0;
  43. $resRemind = db('crm_config')->where(['name' => 'remind_day'])->update(['value' => $remind_day]);
  44. }
  45. $resRemindConfig = db('crm_config')->where(['name' => 'remind_config'])->update(['value' => $remind_config]);
  46. return true;
  47. }
  48. /**
  49. * 获取相关信息
  50. * @author Michael_xu
  51. * @param
  52. * @return
  53. */
  54. public function getData()
  55. {
  56. $list = db('crm_config')->select();
  57. $data = [];
  58. foreach ($list as $k=>$v) {
  59. $data[$v['name']] = $v['value'];
  60. }
  61. return $data ? : [];
  62. }
  63. }