RecipeModel.class.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Model;
  15. class RecipeModel{
  16. public function update($data, $uniacid = 0)
  17. {
  18. $id = $data['data']['id'];
  19. $sp = $data['sp'];
  20. $ins_data = array();
  21. $ins_data['recipe_name'] = $data['data']['recipe_name'];
  22. $ins_data['sub_name'] = $data['sub_name'];
  23. $ins_data['images'] = save_media($data['data']['images']);
  24. $ins_data['video'] = save_media($data['data']['video']);
  25. $ins_data['video'] = D('Seller/Goods')->check_douyin_video($ins_data['video']);
  26. $ins_data['member_id'] = save_media($data['data']['member_id']);
  27. $ins_data['cate_id'] = $data['data']['cate_id'];
  28. $ins_data['make_time'] = $data['data']['make_time'];
  29. $ins_data['diff_type'] = $data['diff_type'];
  30. $ins_data['state'] = isset( $data['state']) ? 1 : 0;
  31. $ins_data['content'] = $data['data']['content'];
  32. $ins_data['addtime'] = time();
  33. if( !empty($id) && $id > 0 )
  34. {
  35. unset($ins_data['addtime']);
  36. M('lionfish_comshop_recipe')->where( array('id' => $id) )->save( $ins_data );
  37. $limit_goods_list = $data['limit_goods_list'];
  38. if( !empty($limit_goods_list) )
  39. {
  40. $save_ingredients_ids = array();
  41. foreach( $limit_goods_list as $val )
  42. {
  43. if($val['id'] <= 0 )
  44. {
  45. //新增 goods_ids
  46. $cai_data = array();
  47. $cai_data['recipe_id'] = $id;
  48. $cai_data['title'] = $val['cai_name'];
  49. $cai_data['addtime'] = time();
  50. $cai_data['goods_id'] = implode(',', $val['goods_ids']);
  51. $insid = M('lionfish_comshop_recipe_ingredients')->add( $cai_data );
  52. $save_ingredients_ids[] = $insid;
  53. }else{
  54. //更新
  55. $save_ingredients_ids[] = $val['id'];
  56. $cai_data = array();
  57. $cai_data['recipe_id'] = $id;
  58. $cai_data['title'] = $val['cai_name'];
  59. $cai_data['goods_id'] = array();
  60. if( !empty($val['goods_ids']) )
  61. $cai_data['goods_id'] = implode(',', $val['goods_ids']);
  62. M('lionfish_comshop_recipe_ingredients')->where( array('id' => $val['id'] ) )->save( $cai_data );
  63. }
  64. }
  65. if( !empty($save_ingredients_ids) )
  66. {
  67. $limit_goods_list_str = implode(',', $save_ingredients_ids );
  68. M('lionfish_comshop_recipe_ingredients')->where( 'id not in (' . $limit_goods_list_str.') and recipe_id = '.$id )->delete();
  69. }
  70. }
  71. }else{
  72. $id = M('lionfish_comshop_recipe')->add( $ins_data );
  73. //判断商品是否存在,先删除一次不存在的, limit_goods_list
  74. $limit_goods_list = $data['limit_goods_list'];
  75. if( !empty($limit_goods_list) )
  76. {
  77. $save_ingredients_ids = array();
  78. foreach( $limit_goods_list as $val )
  79. {
  80. if($val['id'] <= 0 )
  81. {
  82. //新增
  83. $cai_data = array();
  84. $cai_data['recipe_id'] = $id;
  85. $cai_data['title'] = $val['cai_name'];
  86. $cai_data['addtime'] = time();
  87. $cai_data['goods_id'] = implode(',', $val['goods_ids']);
  88. M('lionfish_comshop_recipe_ingredients')->add( $cai_data );
  89. }else{
  90. //更新
  91. $save_ingredients_ids[] = $val['id'];
  92. $cai_data = array();
  93. $cai_data['recipe_id'] = $id;
  94. $cai_data['title'] = $val['cai_name'];
  95. $cai_data['goods_id'] = implode(',', $val['goods_ids']);
  96. M('lionfish_comshop_recipe_ingredients')->where( array('id' => $val['id'] ) )->save( $cai_data );
  97. }
  98. }
  99. if( !empty($save_ingredients_ids) )
  100. {
  101. $limit_goods_list_str = implode(',', $save_ingredients_ids );
  102. M('lionfish_comshop_recipe_ingredients')->where( 'id not in (' . $limit_goods_list_str.') and recipe_id = '.$id )->delete();
  103. }
  104. }
  105. }
  106. }
  107. }
  108. ?>