You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StoreIntegral.php 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. namespace app\model\activity\integral;
  3. use app\model\product\product\StoreDescription;
  4. use app\model\product\product\StoreProduct;
  5. use crmeb\traits\ModelTrait;
  6. use crmeb\basic\BaseModel;
  7. use think\Model;
  8. /**
  9. * 积分商品Model
  10. * Class StoreIntegral
  11. * @package app\model\activity\integral
  12. */
  13. class StoreIntegral extends BaseModel
  14. {
  15. /**
  16. * 数据表主键
  17. * @var string
  18. */
  19. protected $pk = 'id';
  20. /**
  21. * 模型名称
  22. * @var string
  23. */
  24. protected $name = 'store_integral';
  25. use ModelTrait;
  26. /**
  27. * 配送信息
  28. * @param $value
  29. * @return false|string
  30. */
  31. protected function setDeliveryTypeAttr($value)
  32. {
  33. if ($value) {
  34. return is_array($value) ? implode(',', $value) : $value;
  35. }
  36. return '';
  37. }
  38. /**
  39. * 配送信息
  40. * @param $value
  41. * @param $data
  42. * @return mixed
  43. */
  44. protected function getDeliveryTypeAttr($value)
  45. {
  46. if ($value) {
  47. return is_string($value) ? explode(',', $value) : $value;
  48. }
  49. return [];
  50. }
  51. /**
  52. * 配送信息
  53. * @param $value
  54. * @param $data
  55. * @return mixed
  56. */
  57. protected function getCustomFormAttr($value)
  58. {
  59. if ($value) {
  60. return is_string($value) ? json_decode($value, true) : $value;
  61. }
  62. return [];
  63. }
  64. /**
  65. * 商品标签
  66. * @param $value
  67. * @return array|mixed
  68. */
  69. protected function getLabelIdAttr($value)
  70. {
  71. if ($value) {
  72. return is_string($value) ? explode(',', $value) : $value;
  73. }
  74. return [];
  75. }
  76. /**
  77. * 商品保障服务
  78. * @param $value
  79. * @return array|mixed
  80. */
  81. protected function getEnsureAttr($value)
  82. {
  83. if ($value) {
  84. return is_string($value) ? explode(',', $value) : $value;
  85. }
  86. return [];
  87. }
  88. /**
  89. * 参数信息
  90. * @param $value
  91. * @return array|mixed
  92. */
  93. protected function getSpecsAttr($value)
  94. {
  95. if ($value) {
  96. return is_string($value) ? json_decode($value, true) : $value;
  97. }
  98. return [];
  99. }
  100. /**
  101. * 一对一获取原价
  102. * @return \think\model\relation\HasOne
  103. */
  104. public function getPrice()
  105. {
  106. return $this->hasOne(StoreProduct::class, 'id', 'product_id')->bind(['ot_price', 'product_price' => 'price']);
  107. }
  108. /**
  109. * 一对一关联
  110. * 商品关联商品商品详情
  111. * @return \think\model\relation\HasOne
  112. */
  113. public function description()
  114. {
  115. return $this->hasOne(StoreDescription::class, 'product_id', 'id')->where('type', 4)->bind(['description']);
  116. }
  117. /**
  118. * 添加时间获取器
  119. * @param $value
  120. * @return false|string
  121. */
  122. protected function getAddTimeAttr($value)
  123. {
  124. if ($value) return date('Y-m-d H:i:s', (int)$value);
  125. return '';
  126. }
  127. /**
  128. * 轮播图获取器
  129. * @param $value
  130. * @return mixed
  131. */
  132. public function getImagesAttr($value)
  133. {
  134. return json_decode($value, true) ?? [];
  135. }
  136. /**
  137. * 积分商品名称搜索器
  138. * @param Model $query
  139. * @param $value
  140. * @param $data
  141. */
  142. public function searchStoreNameAttr($query, $value, $data)
  143. {
  144. if ($value) $query->where('title|id', 'like', '%' . $value . '%');
  145. }
  146. /**
  147. * 是否推荐搜索器
  148. * @param Model $query
  149. * @param $value
  150. * @param $data
  151. */
  152. public function searchIsHostAttr($query, $value, $data)
  153. {
  154. $query->where('is_host', $value ?? 1);
  155. }
  156. /**
  157. * 状态搜索器
  158. * @param Model $query
  159. * @param $value
  160. * @param $data
  161. */
  162. public function searchIsShowAttr($query, $value, $data)
  163. {
  164. if ($value != '') $query->where('is_show', $value ?: 0);
  165. }
  166. /**
  167. * 是否删除搜索器
  168. * @param Model $query
  169. * @param $value
  170. * @param $data
  171. */
  172. public function searchIsDelAttr($query, $value, $data)
  173. {
  174. $query->where('is_del', $value ?? 0);
  175. }
  176. /**
  177. * 商品ID搜索器
  178. * @param Model $query
  179. * @param $value
  180. * @param $data
  181. */
  182. public function searchProductIdAttr($query, $value, $data)
  183. {
  184. if ($value) {
  185. if (is_array($value)) {
  186. $query->whereIn('product_id', $value);
  187. } else {
  188. $query->where('product_id', $value);
  189. }
  190. }
  191. }
  192. }