Order.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\common\model\store;
  3. use app\common\model\BaseModel;
  4. use app\common\enum\order\OrderTypeEnum;
  5. /**
  6. * 商家门店核销订单记录模型
  7. */
  8. class Order extends BaseModel
  9. {
  10. protected $pk = 'id';
  11. protected $name = 'store_order';
  12. protected $updateTime = false;
  13. /**
  14. * 关联门店表
  15. */
  16. public function store()
  17. {
  18. return $this->BelongsTo("app\\common\\model\\store\\Store", 'store_id', 'store_id');
  19. }
  20. /**
  21. * 关联店员表
  22. */
  23. public function clerk()
  24. {
  25. return $this->BelongsTo("app\\common\\model\\store\\Clerk", 'clerk_id', 'clerk_id');
  26. }
  27. /**
  28. * 关联订单表
  29. */
  30. public function order()
  31. {
  32. return $this->BelongsTo("app\\common\\model\\order\\Order", 'order_id', 'order_id');
  33. }
  34. /**
  35. * 关联供应商表
  36. */
  37. public function supplier()
  38. {
  39. return $this->belongsTo('app\\common\\model\\supplier\\Supplier', 'shop_supplier_id', 'shop_supplier_id')->field(['shop_supplier_id', 'name']);
  40. }
  41. /**
  42. * 订单类型
  43. * @param $value
  44. * @return array
  45. */
  46. public function getOrderTypeAttr($value)
  47. {
  48. $types = OrderTypeEnum::getTypeName();
  49. return ['text' => $types[$value], 'value' => $value];
  50. }
  51. /**
  52. * 新增核销记录
  53. */
  54. public static function add(
  55. $order_id,
  56. $store_id,
  57. $clerk_id,
  58. $shop_supplier_id,
  59. $order_type = OrderTypeEnum::MASTER
  60. )
  61. {
  62. return (new static)->save([
  63. 'order_id' => $order_id,
  64. 'order_type' => $order_type,
  65. 'store_id' => $store_id,
  66. 'clerk_id' => $clerk_id,
  67. 'shop_supplier_id' => $shop_supplier_id,
  68. 'app_id' => self::$app_id
  69. ]);
  70. }
  71. }