config.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. class Model3{
  3. public function filterData($post){
  4. $data=array(
  5. 'back_color'=>$post['back_color'],
  6. 'padding_top'=>$post['padding_top'],
  7. 'padding_bottom'=>$post['padding_bottom'],
  8. 'if_fixed_goods'=>$post['if_fixed_goods'],
  9. 'goods_id'=>isset($post['goods_id'])?$post['goods_id']:array(),
  10. 'goods_count'=>$post['goods_count'],
  11. 'goods_class'=>$post['goods_class'],
  12. 'goods_sort'=>$post['goods_sort'],
  13. );
  14. return ds_callback(true,'',$data);
  15. }
  16. public function formatData($config,$store_id=0){
  17. $config=json_decode($config,true);
  18. $goods_model=model('goods');
  19. $goods_list=array();
  20. if($config['if_fixed_goods']==1){
  21. if(!empty($config['goods_id'])){
  22. $where=array();
  23. if($store_id){
  24. $where[] = array('store_id','=',$store_id);
  25. }
  26. $where[]=array('goods_id','in',array_keys($config['goods_id']));
  27. $goods_list=$goods_model->getGoodsOnlineList($where, '*', 0, 'goods_id desc');
  28. $sorted_goods=array();
  29. foreach($goods_list as $v1){
  30. if(empty($sorted_goods)){
  31. $sorted_goods[]=array_merge($v1,array('sort'=>intval($config['goods_id'][$v1['goods_id']]['sort'])));
  32. }else{
  33. $c=count($sorted_goods);
  34. foreach($sorted_goods as $k2 => $v2){
  35. if($v2['sort']>intval($config['goods_id'][$v1['goods_id']]['sort'])){
  36. array_splice($sorted_goods,$k2,0,array(array_merge($v1,array('sort'=>intval($config['goods_id'][$v1['goods_id']]['sort'])))));
  37. break;
  38. }
  39. }
  40. if($c==count($sorted_goods)){
  41. $sorted_goods[]=array_merge($v1,array('sort'=>intval($config['goods_id'][$v1['goods_id']]['sort'])));
  42. }
  43. }
  44. }
  45. $goods_list=$sorted_goods;
  46. }
  47. }else{
  48. $order='goods_id desc';
  49. switch(intval($config['goods_sort'])){
  50. case 2:
  51. $order='goods_salenum desc';
  52. break;
  53. case 3:
  54. $order='evaluation_good_star desc';
  55. break;
  56. }
  57. $where = array();
  58. if($store_id){
  59. $where[] = array('goodscommon.store_id','=',$store_id);
  60. }
  61. if ($config['goods_class']) {
  62. $where[]=array('goodscommon.gc_id_1|goodscommon.gc_id_2|goodscommon.gc_id_3|goodscommon.gc_id','=',intval($config['goods_class']));
  63. }
  64. //所需字段
  65. $fieldstr = "goods.goods_id,goods.goods_storage,goodscommon.goods_commonid,goodscommon.store_id,goodscommon.goods_name,goodscommon.goods_advword,goodscommon.goods_price,goods.goods_promotion_price,goods.goods_promotion_type,goodscommon.goods_marketprice,goodscommon.goods_image,goods.goods_salenum,goods.evaluation_good_star,goods.evaluation_count";
  66. $fieldstr .= ',goodscommon.is_virtual,goodscommon.is_goodsfcode,goods.is_have_gift,goodscommon.store_name,goodscommon.is_platform_store';
  67. $goods_list = $goods_model->getGoodsUnionList($where,$fieldstr , $order,'goodscommon.goods_commonid', intval($config['goods_count']));
  68. }
  69. $config['goods_list']=$goods_list;
  70. return ds_callback(true,'',$config);
  71. }
  72. }