PropertyOrder.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\common\model\property;
  15. use app\common\model\BaseModel;
  16. use app\common\model\sale\Sale;
  17. use app\common\model\sale\SaleGroup;
  18. use app\common\model\works\ServiceWork;
  19. use app\common\model\works\ServiceWorkAllocateWorkerLog;
  20. use think\facade\Log;
  21. /**
  22. * PropertyOrder模型
  23. * Class PropertyOrder
  24. * @package app\common\model
  25. */
  26. class PropertyOrder extends BaseModel
  27. {
  28. protected $name = 'property_order';
  29. //分配记录
  30. public function allocateWorkerLog()
  31. {
  32. return $this->hasMany(ServiceWorkAllocateWorkerLog::class,'work_id','work_id')->field('*');
  33. }
  34. public function saleGroupInfo()
  35. {
  36. return $this->hasOne(SaleGroup::class, 'id', 'sale_group_id')
  37. ->field('*');
  38. }
  39. public function saleInfo()
  40. {
  41. return $this->hasOne(Sale::class, 'id', 'sale_id')
  42. ->field('*');
  43. }
  44. public function propertyHead()
  45. {
  46. return $this->hasOne(PropertyHead::class, 'id', 'property_head_id')
  47. ->field('*');
  48. }
  49. public function propertyUser()
  50. {
  51. return $this->hasOne(PropertyUser::class, 'id', 'property_user_id')
  52. ->field('*');
  53. }
  54. public function propertyWork()
  55. {
  56. return $this->hasOne(ServiceWork::class, 'id', 'work_id')
  57. ->field('id,real_name,mobile,address,create_time');
  58. }
  59. public function propertyOrderCustomerLog()
  60. {
  61. return $this->hasMany(PropertyOrderCustomerLog::class,'order_id','id')->order(['id'=>'desc']);
  62. }
  63. public static function onBeforeInsert($model){
  64. $propertyHeadInfo = PropertyHead::where('id',$model->property_head_id)->findOrEmpty();
  65. if(!$propertyHeadInfo->isEmpty()){
  66. $propertyHeadInfo = $propertyHeadInfo->toArray();
  67. $model->sale_type = $propertyHeadInfo['sale_type']??0;
  68. $model->sale_id = $propertyHeadInfo['sale_id']??0;
  69. if($propertyHeadInfo['sale_id']){
  70. $saleGroupId = Sale::where('id',$propertyHeadInfo['sale_id'])->value('sale_group_id');
  71. $model->sale_group_id = $saleGroupId??0;
  72. }
  73. }
  74. Log::info('新增物业订单:'.json_encode([$model->property_head_id,$model->sale_type,$model->sale_id,$model->sale_group_id]));
  75. }
  76. }