RecipeModel.class.php 3.7 KB

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