ShopOrderGoods.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\common\model\shops;
  3. use app\common\model\BaseModel;
  4. use app\common\model\dict\DictData;
  5. use think\facade\Cache;
  6. /**
  7. * ShopOrderGoods模型
  8. * Class ShopOrderGoods
  9. * @package app\common\model\shops
  10. */
  11. class ShopOrderGoods extends BaseModel
  12. {
  13. protected $name = 'shop_order_goods';
  14. protected $type = [
  15. 'goods_category_ids' => 'array',
  16. 'goods_banners' => 'array',
  17. ];
  18. public function getSpecArrAttr($value,$data)
  19. {
  20. $value = [];
  21. if(in_array($data['specs_type'], [1,2])){
  22. $value = json_decode($data['specs'],true);
  23. }
  24. if($data['specs_type']== 3){
  25. $customAttributeItems = json_decode($data['custom_attribute_items'],true);
  26. $specs = json_decode($data['specs'],true);
  27. foreach ($specs as $k=>$v){
  28. $specStrArr = explode('-',$v);
  29. $val = [];
  30. foreach($customAttributeItems as $kk=>$vv){
  31. if($specStrArr[0] == $vv['sign']){
  32. $val['title'] = $vv['title'];
  33. $val['sign'] = $vv['sign'];
  34. foreach($vv['spec_items'] as $kkk=>$vvv){
  35. if($specStrArr[1] == $vvv['spec_sign']){
  36. $val += $vvv;
  37. }
  38. }
  39. break;
  40. }
  41. }
  42. $value[] = $val;
  43. }
  44. }
  45. return $value;
  46. }
  47. public function goodsSpecsInventory()
  48. {
  49. return $this->hasOne(ShopGoodSpecsInventory::class,'id','goods_specs_inventory_id');
  50. }
  51. public function getDeliveryTypeTextAttr($value,$data):string
  52. {
  53. $default = Cache::get('DELIVERY_TYPE');
  54. if (!$default) {
  55. $status = DictData::whereIn('type_value', 'delivery_type')->column('name','value');
  56. Cache::set('DELIVERY_TYPE', json_encode($status,true),5);
  57. } else {
  58. $status = json_decode($default,true);
  59. }
  60. return $status[$data['delivery_type']] ?? '';
  61. }
  62. public function getShopGoodsTypeTextAttr($value,$data):string
  63. {
  64. $default = Cache::get('SHOP_GOODS_TYPE');
  65. if (!$default) {
  66. $status = DictData::whereIn('type_value', 'shop_goods_type')->column('name','value');
  67. Cache::set('SHOP_GOODS_TYPE', json_encode($status,true),5);
  68. } else {
  69. $status = json_decode($default,true);
  70. }
  71. return $status[$data['shop_goods_type']] ?? '';
  72. }
  73. }