Order.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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\wow;
  10. use app\common\library\helper;
  11. use app\common\model\BaseModel;
  12. use app\common\enum\OrderType as OrderTypeEnum;
  13. use app\common\service\wechat\wow\Order as WowOrderService;
  14. /**
  15. * 好物圈订单同步记录模型
  16. * Class Order
  17. * @package app\common\model\wow
  18. */
  19. class Order extends BaseModel
  20. {
  21. protected $name = 'wow_order';
  22. protected $alias = 'wow_order';
  23. /**
  24. * 关联用户表
  25. * @return \think\model\relation\BelongsTo
  26. */
  27. public function user()
  28. {
  29. $module = self::getCalledModule() ?: 'common';
  30. return $this->belongsTo("app\\{$module}\\model\\User");
  31. }
  32. /**
  33. * 获取器:最后更新时间
  34. * @param $value
  35. * @return array
  36. */
  37. public function getLastTimeAttr($value)
  38. {
  39. return ['value' => $value, 'text' => date('Y-m-d H:i:s', $value)];
  40. }
  41. /**
  42. * 获取单条记录
  43. * @param $id
  44. * @param $with
  45. * @return static|null
  46. * @throws \think\exception\DbException
  47. */
  48. public static function detail($id, $with = ['goods.image.file', 'user'])
  49. {
  50. return static::get($id, $with);
  51. }
  52. /**
  53. * 添加好物圈订单同步记录(批量)
  54. * @param $wxappId
  55. * @param $orderList
  56. * @param $orderType
  57. * @return array|false
  58. * @throws \Exception
  59. */
  60. public function add($wxappId, $orderList, $orderType = OrderTypeEnum::MASTER)
  61. {
  62. // 批量添加
  63. $saveData = [];
  64. foreach ($orderList as $item) {
  65. $saveData[] = [
  66. 'order_id' => $item['order_id'],
  67. 'user_id' => $item['user_id'],
  68. 'order_type' => $orderType,
  69. 'status' => WowOrderService::getStatusByOrder($item),
  70. 'last_time' => time(),
  71. 'wxapp_id' => $wxappId,
  72. ];
  73. }
  74. return $this->isUpdate(false)->saveAll($saveData);
  75. }
  76. /**
  77. * 更新好物圈订单同步记录(批量)
  78. * @param $legalList
  79. * @return array|false
  80. * @throws \Exception
  81. */
  82. public function edit($legalList)
  83. {
  84. // 批量更新
  85. $saveData = [];
  86. foreach ($legalList as $id => $item) {
  87. $saveData[] = [
  88. 'id' => $id,
  89. 'status' => WowOrderService::getStatusByOrder($item),
  90. 'last_time' => time(),
  91. ];
  92. }
  93. return $this->isUpdate()->saveAll($saveData);
  94. }
  95. /**
  96. * 软删除
  97. * @return false|int
  98. */
  99. public function setDelete()
  100. {
  101. return $this->save(['is_delete' => 1]);
  102. }
  103. /**
  104. * 根据订单id集和订单类型获取记录
  105. * @param array $orderIds
  106. * @param int $orderType
  107. * @return false|\PDOStatement|string|\think\Collection
  108. * @throws \think\db\exception\DataNotFoundException
  109. * @throws \think\db\exception\ModelNotFoundException
  110. * @throws \think\exception\DbException
  111. */
  112. public function getListByOrderIds($orderIds, $orderType = OrderTypeEnum::MASTER)
  113. {
  114. return $this->where('order_id', 'in', $orderIds)
  115. ->where('order_type', '=', $orderType)
  116. ->where('is_delete', '=', 0)
  117. ->select();
  118. }
  119. }