UserRiceDelivery.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace app\common\model\card;
  3. use app\common\enum\order\DeliveryStatus;
  4. use app\common\enum\order\ReceiptStatus;
  5. use app\common\model\BaseModel;
  6. use app\common\model\UploadFile;
  7. use app\common\model\chef\ChefAreas as RegionModel;
  8. /**
  9. * 米卡配送模型
  10. * @package app\common\model
  11. */
  12. class UserRiceDelivery extends BaseModel
  13. {
  14. protected $name = 'user_rice_delivery';
  15. /**
  16. * 追加字段
  17. * @var array
  18. */
  19. protected $append = ['region','status_text'];
  20. /**
  21. * 获取器:地区名称
  22. * @param $value
  23. * @param $data
  24. * @return array
  25. * @throws \think\db\exception\DataNotFoundException
  26. * @throws \think\db\exception\DbException
  27. * @throws \think\db\exception\ModelNotFoundException
  28. */
  29. public function getRegionAttr($value, $data)
  30. {
  31. return [
  32. 'province' => RegionModel::getNameById($data['province_id']),
  33. 'city' => RegionModel::getNameById($data['city_id']),
  34. 'region' => RegionModel::getNameById($data['region_id'])
  35. ];
  36. }
  37. /**
  38. * 发货时间
  39. * @param $value
  40. * @return false|string
  41. */
  42. public function getDeliveryTimeAttr($value)
  43. {
  44. return format_time($value);
  45. }
  46. /**
  47. * 收货时间
  48. * @param $value
  49. * @return false|string
  50. */
  51. public function getReceiptTimeAttr($value)
  52. {
  53. return format_time($value);
  54. }
  55. /**
  56. * 一对一关联米卡
  57. */
  58. public function userRiceCard()
  59. {
  60. return $this->belongsTo('UserRiceCard', 'user_rice_card_id','id');
  61. }
  62. /**
  63. * 一对多关联配送物流表
  64. */
  65. public function userRiceDeliveryExpress()
  66. {
  67. return $this->hasMany('UserRiceDeliveryExpress', 'user_rice_delivery_id','id');
  68. }
  69. public function getStatusTextAttr($value,$data){
  70. if($data['delivery_status']==DeliveryStatus::NOT_DELIVERED){
  71. return ['code'=>1,'text'=>'待配送'];
  72. }elseif($data['delivery_status']==DeliveryStatus::DELIVERED && $data['receipt_status']==ReceiptStatus::NOT_RECEIVED){
  73. return ['code'=>2,'text'=>'配送中'];
  74. }elseif($data['receipt_status']==ReceiptStatus::RECEIVED){
  75. return ['code'=>3,'text'=>'配送完成'];
  76. }
  77. return ['code'=>1,'text'=>'配送完成'];
  78. }
  79. /**
  80. * 获取记录
  81. * @param int $id
  82. * @param array $with
  83. * @return static
  84. */
  85. public static function detail(int $id, array $with = [])
  86. {
  87. return static::get($id, $with);
  88. }
  89. }