Order.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace addons\qingdongams\model;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. /**
  6. *订单
  7. */
  8. class Order extends Model
  9. {
  10. use SoftDelete;
  11. // 开启自动写入时间戳字段
  12. protected $autoWriteTimestamp = 'int';
  13. // 定义时间戳字段名
  14. protected $createTime = 'createtime';
  15. protected $updateTime = 'updatetime';
  16. protected $deleteTime = 'deletetime';
  17. protected $name = 'qingdongams_order';
  18. protected $append = [
  19. 'show_staff_data',
  20. ];
  21. public function getShowStaffDataAttr($value,$data)
  22. {
  23. if (!isset($data['show_staff_id'])) {
  24. return '';
  25. }
  26. $ids=explode(',',$data['show_staff_id']);
  27. return Staff::where(['id'=>['in',$ids]])->field('id,name,img,post,mobile')->select();
  28. }
  29. //获取更新时间
  30. public function getCreatetimeAttr($value) {
  31. return date('Y-m-d H:i:s', $value);
  32. }
  33. //负责人
  34. public function createStaff() {
  35. return $this->hasOne(Staff::class, 'id', 'create_staff_id')->field('id,name');
  36. }
  37. //负责人
  38. public function ownerStaff() {
  39. return $this->hasOne(Staff::class, 'id', 'owner_staff_id')->field('id,name');
  40. }
  41. //客户
  42. public function customer() {
  43. return $this->hasOne(Customer::class, 'id', 'customer_id')->field('id,name,follow,address');
  44. }
  45. //联系人
  46. public function contacts() {
  47. return $this->hasOne(Contacts::class, 'id', 'contacts_id')->field('id,name');
  48. }
  49. //合同
  50. public function contract() {
  51. return $this->hasOne(Contract::class, 'id', 'contract_id')
  52. ->field('id,name,num,money');
  53. }
  54. //产品
  55. public function product(){
  56. return $this->hasMany(ContractProduct::class,'contract_id','contract_id')->with('product');
  57. }
  58. }