StoreOrderCartInfo.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/12/26
  6. */
  7. namespace app\models\store;
  8. use crmeb\basic\BaseModel;
  9. use crmeb\traits\ModelTrait;
  10. /**
  11. * TODO 订单记录Model
  12. * Class StoreOrderCartInfo
  13. * @package app\models\store
  14. */
  15. class StoreOrderCartInfo extends BaseModel
  16. {
  17. /**
  18. * 模型名称
  19. * @var string
  20. */
  21. protected $name = 'store_order_cart_info';
  22. use ModelTrait;
  23. public static function getCartInfoAttr($value)
  24. {
  25. return json_decode($value, true) ?: [];
  26. }
  27. public static function setCartInfo($oid, array $cartInfo)
  28. {
  29. $group = [];
  30. foreach ($cartInfo as $cart) {
  31. $group[] = [
  32. 'oid' => $oid,
  33. 'cart_id' => $cart['id'],
  34. 'product_id' => $cart['productInfo']['id'],
  35. 'cart_info' => json_encode($cart),
  36. 'unique' => md5($cart['id'] . '' . $oid),
  37. 'store_id' => $cart['productInfo']['store_id'],
  38. 'return_money' => ($cart['productInfo']['is_sub'] && isset($cart['productInfo']['attrInfo'])) ? $cart['productInfo']['attrInfo']['return_money'] : ($cart['productInfo']['return_money'] ?? 0),
  39. 'return_money_type' => ($cart['productInfo']['is_sub'] && isset($cart['productInfo']['attrInfo'])) ? $cart['productInfo']['attrInfo']['return_money_type'] : ($cart['productInfo']['return_money_type'] ?? ''),
  40. 'return_day' => ($cart['productInfo']['is_sub'] && isset($cart['productInfo']['attrInfo'])) ? $cart['productInfo']['attrInfo']['return_day'] : ($cart['productInfo']['return_day'] ?? 1),
  41. ];
  42. }
  43. return self::setAll($group);
  44. }
  45. public static function getProductNameList($oid)
  46. {
  47. $cartInfo = self::where('oid', $oid)->select();
  48. $goodsName = [];
  49. foreach ($cartInfo as $cart) {
  50. $suk = isset($cart['cart_info']['productInfo']['attrInfo']) ? '(' . $cart['cart_info']['productInfo']['attrInfo']['suk'] . ')' : '';
  51. $goodsName[] = $cart['cart_info']['productInfo']['store_name'] . $suk;
  52. }
  53. return $goodsName;
  54. }
  55. }