PropertyOrder.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\works\ServiceWork;
  18. use think\facade\Log;
  19. /**
  20. * PropertyOrder模型
  21. * Class PropertyOrder
  22. * @package app\common\model
  23. */
  24. class PropertyOrder extends BaseModel
  25. {
  26. protected $name = 'property_order';
  27. public function propertyHead()
  28. {
  29. return $this->hasOne(PropertyHead::class, 'id', 'property_head_id')
  30. ->field('*');
  31. }
  32. public function propertyUser()
  33. {
  34. return $this->hasOne(PropertyUser::class, 'id', 'property_user_id')
  35. ->field('*');
  36. }
  37. public function propertyWork()
  38. {
  39. return $this->hasOne(ServiceWork::class, 'id', 'work_id')
  40. ->field('id,real_name,mobile,address,create_time');
  41. }
  42. public static function onBeforeInsert($model){
  43. $propertyHeadInfo = PropertyHead::where('id',$model->property_head_id)->findOrEmpty();
  44. if(!$propertyHeadInfo->isEmpty()){
  45. $propertyHeadInfo = $propertyHeadInfo->toArray();
  46. $model->sale_type = $propertyHeadInfo['sale_type']??0;
  47. $model->sale_id = $propertyHeadInfo['sale_id']??0;
  48. if($propertyHeadInfo['sale_id']){
  49. $saleGroupId = Sale::where('id',$propertyHeadInfo['sale_id'])->value('sale_group_id');
  50. $model->sale_group_id = $saleGroupId??0;
  51. }
  52. }
  53. Log::info('新增物业订单:'.json_encode([$model->property_head_id,$model->sale_type,$model->sale_id,$model->sale_group_id]));
  54. }
  55. }