Order.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\common\model\store\shop;
  3. use app\common\model\BaseModel;
  4. use app\common\enum\OrderType as OrderTypeEnum;
  5. /**
  6. * 商家门店核销订单记录模型
  7. * Class Clerk
  8. * @package app\common\model\store
  9. */
  10. class Order extends BaseModel
  11. {
  12. protected $name = 'store_shop_order';
  13. protected $updateTime = false;
  14. /**
  15. * 关联门店表
  16. * @return \think\model\relation\BelongsTo
  17. */
  18. public function shop()
  19. {
  20. $module = static::getCalledModule() ?: 'common';
  21. return $this->BelongsTo("app\\{$module}\\model\\store\\Shop");
  22. }
  23. /**
  24. * 关联店员表
  25. * @return \think\model\relation\BelongsTo
  26. */
  27. public function clerk()
  28. {
  29. $module = static::getCalledModule() ?: 'common';
  30. return $this->BelongsTo("app\\{$module}\\model\\store\\shop\\Clerk");
  31. }
  32. /**
  33. * 订单类型
  34. * @param $value
  35. * @return array
  36. */
  37. public function getOrderTypeAttr($value)
  38. {
  39. $types = OrderTypeEnum::getTypeName();
  40. return ['text' => $types[$value], 'value' => $value];
  41. }
  42. /**
  43. * 新增核销记录
  44. * @param int $order_id 订单id
  45. * @param int $shop_id 门店id
  46. * @param int $clerk_id 核销员id
  47. * @param int $order_type
  48. * @return mixed
  49. */
  50. public static function add(
  51. $order_id,
  52. $shop_id,
  53. $clerk_id,
  54. $order_type = OrderTypeEnum::MASTER
  55. )
  56. {
  57. return (new static)->save([
  58. 'order_id' => $order_id,
  59. 'order_type' => $order_type,
  60. 'shop_id' => $shop_id,
  61. 'clerk_id' => $clerk_id,
  62. 'wxapp_id' => static::$wxapp_id
  63. ]);
  64. }
  65. }