goods_id倒序排线 * @return array */ public static function list (array $map = [], array $paginate = [], array $orderMap = [], $filter) { $field = 'sort,category,goods_sn,goods_name,goods_img,min_original_price as original_price,min_price as price,rebate_score,sales_volume,inventory,attension_count,restrictions_num'; $order = 'sort desc,goods_id desc'; foreach ($map as $k => $v) { if (empty($v)) { unset($map[$k]); } } if (isset($map['ids'])) { $list['data'] = self::where(['goods_sn' => $map['ids']])->field($field)->select()->toArray(); } else { if (!empty($orderMap['sort'])) { switch (intval($orderMap['sort'])) { case 1: // $order = 'goods_id asc'; $order = 'sort desc'; break; case 2: $order = 'attension_count asc'; break; case 3: $order = 'created_time desc'; break; case 4: // 价格降序 $order = 'price desc'; break; case 5: $order = 'price asc'; break; case 6: $order = 'sales_volume desc'; break; case 7: $order = 'sales_volume asc'; break; case 8: $order = 'rebate_score asc'; break; case 9: $order = 'rebate_score desc'; break; case 10: $order = 'rebate_score asc'; break; case 11: // 10积分升序 $order = 'rebate_score desc'; break; default: break; } } $where = []; // if ($filter){ // // $price = explode('-', $filter['price']); // $redscore = explode('-', $filter['redscore']); // $score = explode('-', $filter['score']); // if (count($price) == 2){ // if (!empty($price[0])){ // $where[] = ['price', '>', $price[0]]; // } // // if (!empty($price[1])){ // $where[] = ['price', '<', $price[1]]; // } // // // // } // // if (count($redscore) == 2){ // if (!empty($redscore[0])){ // $where[] = ['rebate_score_lock', '>', $redscore[0]]; // } // // if (!empty($redscore[1])){ // $where[] = ['rebate_score_lock', '<', $redscore[1]]; // } // } // // if (count($score) == 2){ // if (!empty($score[0])){ // $where[] = ['rebate_score_most', '>', $score[0]]; // } // // if (!empty($score[1])){ // $where[] = ['rebate_score_most', '<', $score[1]]; // } // // // } // // // } if (isset($map['menu_id']) && intval($map['menu_id']) > 0){ $where[] = ['menu_id', '=', $map['menu_id']]; unset($map['menu_id']); } if (!empty($map['keywords'])) { $where[] = ['goods_name|hot_keywords', 'like', "%{$map['keywords']}%"]; unset($map['keywords']); } if (!empty($map['cls'])) { $where[] = ['give_vip', '>', 0]; unset($map['cls']); } // if (!empty($map['category_id']) && $map['category_id'] != 0) { // $where[] = ['category', '=', $map['category_id']]; // unset($map['category_id']); // } $where[] = ['on_sale', '=', 1]; $list = self::where($map)->where($where)->field($field)->order($order)->paginate($paginate['limit'])->toArray(); } // if ($map['goods_type'] == 1){ //// $cur_xzmoney = Db::name('system_config')->where('name', 'xz_cur_money')->where('group', 'xzconfig')->value('value'); // foreach ($list['data'] as $key=>$val){ // if ($val['goods_type'] == 1){ // //// $list['data'][$key]['price'] = getXzPirceWithPrice($cur_xzmoney, $val['price']); // } // } // } // return sr_getLastSql(); return $list['data']; } public static function details (array $map, ?string $field = '*'): array { $cache = false; if (($goodsBase = \services\CacheServices::get(md5('goodsDetail_' . $map['goods_sn']))) === false || empty($goodsBase)) { $field = 'menu_id,spec_name,goods_id,category,goods_sn,goods_name,goods_img,goods_img_banner,goods_remark,min_original_price as original_price,min_price as price,note,inventory,rebate_score,sales_volume,restrictions,rush_buy,buynote_template as buyNote,post_template_id,restrictions_num'; $goodsBase = self::where(['goods_sn' => $map['goods_sn']])->field($field)->withAttr('goods_img_banner', function ($value) { return json_decode($value, true) ?: []; })->withAttr('goods_remark', function ($value) { return htmlspecialchars_decode($value); })->withAttr('buyNote', function ($value) { return htmlspecialchars_decode($value); })->findOrEmpty()->toArray(); if (empty($goodsBase)) return []; $specRelation = Db::name('shop_goods_spec_relation')->field('spec_name,spec_value')->where(['goods_id' => $goodsBase['goods_id']])->withAttr('spec_value', function ($value) { return json_decode($value, true); })->select()->toArray(); $goodsExpress = Db::name('express_delivery')->where(['id' => $goodsBase['post_template_id']])->findOrEmpty(); $goodsSpec = Db::name('shop_goods_spec')->field('spec_ids,spec_text,original_price,price,picture,stock')->where(['goods_id' => $goodsBase['goods_id']])->select()->toArray(); $goodsBase['expressNote'] = $goodsExpress['remake'] ?: ''; $goodsBase['spec_relation'] = $specRelation; $goodsBase['goods_spec'] = $goodsSpec; // if ($goodsBase['goods_type'] == 5){ // $cur_xzmoney = Db::name('system_config')->where('name', 'xz_cur_money')->where('group', 'xzconfig')->value('value'); // $goodsBase['price'] = getXzPirceWithPrice($cur_xzmoney, $goodsBase['price']); // } $cache = true; \services\CacheServices::set(md5('goodsDetail_' . $map['goods_sn']), $goodsBase); } if (empty($cache)) { $goodsSpec = Db::name('shop_goods_spec')->field('spec_ids,spec_text,original_price,price,picture,stock')->where(['goods_id' => $goodsBase['goods_id']])->select()->toArray(); $goodsBase['goods_spec'] = $goodsSpec; } // if ($goodsBase['goods_type'] == 5){ // $cur_xzmoney = Db::name('system_config')->where('name', 'xz_cur_money')->where('group', 'xzconfig')->value('value'); // foreach ($goodsBase['goods_spec'] as $key=>&$val){ // $val['price'] = getXzPirceWithPrice($cur_xzmoney, floatval($val['price'])); // } // } return $goodsBase; } }