CustomerChance.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. namespace app\customer\model;
  14. use think\model;
  15. use think\facade\Db;
  16. class CustomerChance extends Model
  17. {
  18. /**
  19. * 获取分页列表
  20. * @param $where
  21. * @param $param
  22. */
  23. public function datalist($param=[],$where=[])
  24. {
  25. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  26. $order = empty($param['order']) ? 'a.id desc' : $param['order'];
  27. try {
  28. $list = self::where($where)
  29. ->field('a.*')
  30. ->alias('a')
  31. ->join('Customer c','a.cid = c.id')
  32. ->order($order)
  33. ->paginate(['list_rows'=> $rows])
  34. ->each(function ($item, $key){
  35. $item->customer = Db::name('Customer')->where(['id' => $item->cid])->value('name');
  36. $item->belong_name = Db::name('Admin')->where('id',$item->belong_uid)->value('name');
  37. $item->stage_name = Db::name('BasicCustomer')->where(['id' => $item->stage])->value('title');
  38. $item->expected_time = date('Y-m-d', $item->expected_time);
  39. $item->discovery_time = date('Y-m-d', $item->discovery_time);
  40. $item->is_contract = Db::name('Contract')->where(['chance_id'=>$item->id,'delete_time'=>0])->count();
  41. });
  42. return $list;
  43. } catch(\Exception $e) {
  44. return ['code' => 1, 'data' => [], 'msg' => $e->getMessage()];
  45. }
  46. }
  47. /**
  48. * 添加数据
  49. * @param $param
  50. */
  51. public function add($param)
  52. {
  53. $insertId = 0;
  54. try {
  55. $param['create_time'] = time();
  56. $insertId = self::strict(false)->field(true)->insertGetId($param);
  57. add_log('add', $insertId, $param);
  58. } catch(\Exception $e) {
  59. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  60. }
  61. return to_assign(0,'操作成功',['return_id'=>$insertId]);
  62. }
  63. /**
  64. * 编辑信息
  65. * @param $param
  66. */
  67. public function edit($param)
  68. {
  69. try {
  70. $param['update_time'] = time();
  71. self::where('id', $param['id'])->strict(false)->field(true)->update($param);
  72. add_log('edit', $param['id'], $param);
  73. } catch(\Exception $e) {
  74. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  75. }
  76. return to_assign(0,'操作成功',['return_id'=>$param['id']]);
  77. }
  78. /**
  79. * 根据id获取信息
  80. * @param $id
  81. */
  82. public function getById($id)
  83. {
  84. $info = self::find($id);
  85. $info['customer'] = Db::name('Customer')->where(['id' => $info['cid']])->value('name');
  86. $info['belong_name'] = Db::name('Admin')->where(['id' => $info['belong_uid']])->value('name');
  87. $assist_names = Db::name('Admin')->where([['id','in',$info['assist_ids']]])->column('name');
  88. $info['assist_names'] = implode(',',$assist_names);
  89. $contract = Db::name('Contract')->where(['chance_id'=>$info['id'],'delete_time'=>0])->find();
  90. if(!empty($contract)){
  91. $info['contract'] = $contract['name'];
  92. $info['contract_id'] = $contract['id'];
  93. }
  94. return $info;
  95. }
  96. /**
  97. * 删除信息
  98. * @param $id
  99. * @param $type
  100. * @return array
  101. */
  102. public function delById($id,$type=0)
  103. {
  104. if($type==0){
  105. //逻辑删除
  106. try {
  107. $param['delete_time'] = time();
  108. self::where('id', $id)->update(['delete_time'=>time()]);
  109. add_log('delete', $id);
  110. } catch(\Exception $e) {
  111. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  112. }
  113. }
  114. else{
  115. //物理删除
  116. try {
  117. self::destroy($id);
  118. add_log('delete', $id);
  119. } catch(\Exception $e) {
  120. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  121. }
  122. }
  123. return to_assign();
  124. }
  125. }