StoreOrderCartInfo.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\order;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. use think\Model;
  15. /**
  16. * TODO 订单记录Model
  17. * Class StoreOrderCartInfo
  18. * @package app\model\order
  19. */
  20. class StoreOrderCartInfo extends BaseModel
  21. {
  22. use ModelTrait;
  23. /**
  24. * 数据表主键
  25. * @var string
  26. */
  27. protected $pk = 'id';
  28. /**
  29. * 模型名称
  30. * @var string
  31. */
  32. protected $name = 'store_order_cart_info';
  33. /**
  34. * 购物车信息获取器
  35. * @param $value
  36. * @return array|mixed
  37. */
  38. public function getCartInfoAttr($value)
  39. {
  40. return json_decode($value, true) ?? [];
  41. }
  42. /**
  43. * 订单ID搜索器
  44. * @param Model $query
  45. * @param $value
  46. * @param $data
  47. */
  48. public function searchOidAttr($query, $value, $data)
  49. {
  50. if ($value !== '') $query->where('oid', $value);
  51. }
  52. /**
  53. * 购物车ID搜索器
  54. * @param Model $query
  55. * @param $value
  56. * @param $data
  57. */
  58. public function searchCartIdAttr($query, $value, $data)
  59. {
  60. if (is_array($value)) {
  61. $query->whereIn('cart_id', $value);
  62. } else {
  63. $query->where('cart_id', $value);
  64. }
  65. }
  66. /**
  67. * 原购物车ID搜索器
  68. * @param Model $query
  69. * @param $value
  70. * @param $data
  71. */
  72. public function searchOldCartIdAttr($query, $value, $data)
  73. {
  74. if (is_array($value)) {
  75. $query->whereIn('old_cart_id', $value);
  76. } else {
  77. $query->where('old_cart_id', $value);
  78. }
  79. }
  80. /**
  81. * 拆分状态搜索器
  82. * @param Model $query
  83. * @param $value
  84. * @param $data
  85. */
  86. public function searchSplitStatusAttr($query, $value)
  87. {
  88. if (is_array($value)) {
  89. $query->whereIn('split_status', $value);
  90. } else {
  91. if (in_array($value, [0, 1, 2])) {
  92. $query->where('split_status', $value);
  93. }
  94. }
  95. }
  96. }