CompanyDispatch.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class CompanyDispatch extends Base
  5. {
  6. protected $createTime = 'create_time';
  7. protected $updateTime = 'update_time';
  8. public $table = 'company_dispatch';
  9. protected $validateName = 'CompanyDispatch';
  10. public $status = [
  11. '待确认',
  12. '已确认',
  13. '已取消',
  14. ];
  15. public function saveData($data){
  16. $data['create_time'] = date('Y-m-d H:i:s');
  17. $data['user_id'] = is_login();
  18. $data['sn'] = get_unique_id();
  19. $ret = $this->allowField(true)->save($data);
  20. if(!$ret){
  21. $this->error = '操作失败';
  22. return false;
  23. }
  24. return $this->getLastInsID();
  25. }
  26. public function getInfo($id){
  27. $info = $this
  28. ->where('id',$id)
  29. ->find()
  30. ->toArray();
  31. if(!$info){
  32. return false;
  33. }
  34. $info['userName'] = Db::name('user')
  35. ->where('id',$info['user_id'])
  36. ->value('real_name');
  37. $info['goods'] = Db::name('company_dispatch_goods')
  38. ->alias('a')
  39. ->join('mate_goods b','a.goods_id=b.id')
  40. ->where('a.dispatch_id',$info['id'])
  41. ->field('a.*,b.title,b.unit,b.brand,b.spec')
  42. ->select();
  43. return $info;
  44. }
  45. }