Order.php 1.8 KB

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