InvoiceInfoLogic.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * 发票开户行逻辑类
  4. *
  5. * @author qifan
  6. * @date 2020-12-19
  7. */
  8. namespace app\crm\model;
  9. use think\Db;
  10. class InvoiceInfoLogic
  11. {
  12. /**
  13. * 列表
  14. *
  15. * @param $param
  16. * @return bool|\PDOStatement|string|\think\Collection
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. * @throws \think\exception\DbException
  20. */
  21. public function index($param)
  22. {
  23. $where = [];
  24. if (!empty($param['customer_id'])) {
  25. $where['customer_id'] = $param['customer_id'];
  26. }
  27. $list = Db::name('crm_invoice_info')->alias('info')
  28. ->join('admin_user user', 'user.id=info.create_user_id')
  29. ->field('info.*,user.realname as create_user_name')
  30. ->where($where)->select();
  31. $count = Db::name('crm_invoice_info')->alias('info')
  32. ->join('admin_user user', 'user.id=info.create_user_id')
  33. ->where($where)->count();
  34. foreach ($list as $k => $v) {
  35. $list[$k]['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
  36. }
  37. return ['count' => $count, 'list' => $list];
  38. }
  39. /**
  40. * 详情
  41. *
  42. * @param $infoId
  43. * @return array|bool|\PDOStatement|string|\think\Model|null
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. * @throws \think\exception\DbException
  47. */
  48. public function read($infoId)
  49. {
  50. return Db::name('crm_invoice_info')->field(['customer_id', 'create_user_id', 'create_time', 'update_time'], true)
  51. ->where('info_id', $infoId)->find();
  52. }
  53. /**
  54. * 创建
  55. *
  56. * @param $param
  57. * @return int|string
  58. */
  59. public function save($param)
  60. {
  61. $param['create_user_id'] = $param['user_id'];
  62. $param['create_time'] = time();
  63. $param['update_time'] = $param['create_time'];
  64. unset($param['user_id']);
  65. return Db::name('crm_invoice_info')->insert($param);
  66. }
  67. /**
  68. * 编辑
  69. *
  70. * @param $param
  71. * @return int|string
  72. * @throws \think\Exception
  73. * @throws \think\exception\PDOException
  74. */
  75. public function update($param)
  76. {
  77. $param['update_time'] = time();
  78. return Db::name('crm_invoice_info')->strict(true)->update($param);
  79. }
  80. /**
  81. * 删除
  82. *
  83. * @param $infoId
  84. * @return int
  85. * @throws \think\Exception
  86. * @throws \think\exception\PDOException
  87. */
  88. public function delete($infoId)
  89. {
  90. return Db::name('crm_invoice_info')->where('info_id', $infoId)->delete();
  91. }
  92. }