StoreOrderCartInfo.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. ];
  38. }
  39. return self::setAll($group);
  40. }
  41. public static function getProductNameList($oid)
  42. {
  43. $cartInfo = self::where('oid',$oid)->select();
  44. $goodsName = [];
  45. foreach ($cartInfo as $cart){
  46. $suk = isset($cart['cart_info']['productInfo']['attrInfo']) ? '('.$cart['cart_info']['productInfo']['attrInfo']['suk'].')' : '';
  47. $goodsName[] = $cart['cart_info']['productInfo']['store_name'].$suk;
  48. }
  49. return $goodsName;
  50. }
  51. public static function getcartinfo($oid)
  52. {
  53. return self::where('oid',$oid)->select();
  54. }
  55. /**
  56. * 获取订单数据商品
  57. * @param $oid
  58. * @return array
  59. * @throws \think\db\exception\DataNotFoundException
  60. * @throws \think\db\exception\DbException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. * @throws \think\exception\DbException
  63. */
  64. public static function getProductList($oid)
  65. {
  66. $cartInfo = self::where('oid',$oid)->select();
  67. $cartlist = [];
  68. foreach ($cartInfo as $cart){
  69. $cartlist[] = $cart['cart_info'];
  70. }
  71. return $cartlist;
  72. }
  73. /**
  74. * 获取订单数量
  75. * @param $oid
  76. * @return int
  77. * @throws \think\db\exception\DataNotFoundException
  78. * @throws \think\db\exception\DbException
  79. * @throws \think\db\exception\ModelNotFoundException
  80. * @throws \think\exception\DbException
  81. */
  82. public static function getProductcount($oid)
  83. {
  84. $cartlist = self::getProductList($oid);
  85. $sum = 0;
  86. foreach ($cartlist as $v)
  87. {
  88. if(isset($v['attrInfo']['suk'])) {
  89. $sum += intval($v['attrInfo']['suk']);
  90. }
  91. }
  92. return $sum;
  93. }
  94. }