SalesroomModel.class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 zcy 2020-09-18
  12. *
  13. */
  14. namespace Seller\Model;
  15. class SalesroomModel{
  16. public function update($data)
  17. {
  18. $ins_data = array();
  19. $ins_data['supply_id'] = $data['supply_id'];
  20. $ins_data['room_name'] = $data['room_name'];
  21. $ins_data['room_logo'] = $data['room_logo'];
  22. $ins_data['province_id'] = $data['province_id'];
  23. $ins_data['city_id'] = $data['city_id'];
  24. $ins_data['country_id'] = $data['country_id'];
  25. $ins_data['address'] = $data['address'];
  26. $ins_data['lon'] = $data['lon'];
  27. $ins_data['lat'] = $data['lat'];
  28. $ins_data['mobile'] = $data['mobile'];
  29. $ins_data['business_hours_begin'] = $data['business_hours_begin'];
  30. $ins_data['business_hours_end'] = $data['business_hours_end'];
  31. $ins_data['contacts'] = $data['contacts'];
  32. $ins_data['introduction'] = $data['introduction'];
  33. $ins_data['displayorder'] = $data['displayorder'];
  34. $ins_data['state'] = $data['state'];
  35. $room_address = $data['province_id'].$data['city_id'].$data['country_id'].$data['address'];
  36. $ins_data['room_address'] = $room_address;
  37. $id = $data['id'];
  38. if( !empty($id) && $id > 0 )
  39. {
  40. unset($ins_data['id']);
  41. M('lionfish_comshop_salesroom')->where( array('id' => $id) )->save( $ins_data );
  42. if($data['state'] == 0){
  43. D('Seller/Salesroom')->update_hxgoods($id);
  44. }
  45. }else{
  46. $ins_data['addtime'] = time();
  47. $id = M('lionfish_comshop_salesroom')->add( $ins_data );
  48. }
  49. }
  50. public function querySalesRoom(){
  51. $list = M('lionfish_comshop_salesroom')->field('id,room_name,supply_id')->where( array('state' => 1 ) )->order('displayorder desc')->select();
  52. foreach ($list as $k=>$v) {
  53. if(empty($v['supply_id'])){
  54. $list[$k]['supply_name'] = "平台";
  55. }else{
  56. $supply_info = M('lionfish_comshop_supply')->where( array('id' => $v['supply_id']) )->field('shopname')->find();
  57. $list[$k]['supply_name'] = $supply_info['shopname'];
  58. }
  59. }
  60. return $list;
  61. }
  62. /**
  63. * 删除门店后商品恢复成普通商品(如果指定门店且只有一个门店的时候)
  64. * @param $salesroom_id
  65. */
  66. public function update_hxgoods($salesroom_id){
  67. $salesroom_info = M('lionfish_comshop_salesroom')->where( array('id' => $salesroom_id) )->find();
  68. $supply_id = $salesroom_info['supply_id'];
  69. $salesroom_count = M('lionfish_comshop_salesroom')->where( array('supply_id' => $supply_id,'state'=>1) )->count();
  70. if($salesroom_count > 0){
  71. $this->update_salesroom_goods($salesroom_id);
  72. }else{
  73. $goods_list = M('lionfish_comshop_good_common')->where( array('supply_id' => $supply_id,'is_only_hexiao'=>1) )->select();
  74. foreach($goods_list as $k=>$v){
  75. $goods_id = $v['goods_id'];
  76. $goods_salesroom_list = M('lionfish_comshop_goods_relative_salesroom')->where( array('goods_id' => $goods_id) )->select();
  77. //删除商品关联门店信息
  78. M('lionfish_comshop_goods_relative_salesroom')->where( array('goods_id'=>$goods_id) )->delete();
  79. foreach($goods_salesroom_list as $gk=>$gv){
  80. //删除商品关联门店核销员信息
  81. M('lionfish_comshop_goods_relative_smember')->where( array('gr_id'=>$gv['id']) )->delete();
  82. }
  83. //删除商品核销信息表
  84. M('lionfish_comshop_goods_salesroombase')->where( array('goods_id' => $goods_id) )->delete();
  85. //更新商品为无核销状态
  86. M('lionfish_comshop_good_common')->where( array('goods_id' => $goods_id) )->save(array('is_only_hexiao'=>0));
  87. }
  88. }
  89. }
  90. public function update_salesroom_goods($salesroom_id){
  91. $goods_salesroom_list = M('lionfish_comshop_goods_relative_salesroom')->where( array('salesroom_id' => $salesroom_id) )->select();
  92. foreach($goods_salesroom_list as $k=>$v){
  93. $goods_id = $v['goods_id'];
  94. //删除商品关联门店信息
  95. M('lionfish_comshop_goods_relative_salesroom')->where( array('salesroom_id' => $salesroom_id,'goods_id'=>$goods_id) )->delete();
  96. //删除商品关联门店核销员信息
  97. M('lionfish_comshop_goods_relative_smember')->where( array('salesroom_id' => $salesroom_id,'gr_id'=>$v['id']) )->delete();
  98. $goods_salesroombase = M('lionfish_comshop_goods_salesroombase')->where( array('goods_id' => $goods_id) )->find();
  99. if(!empty($goods_salesroombase)){
  100. //如果商品是指定核销员
  101. if($goods_salesroombase['hx_assign_salesroom'] == 1){
  102. $count = M('lionfish_comshop_goods_relative_salesroom')->where( array('goods_id'=>$goods_id) )->count();
  103. //商品无关联门店信息
  104. if($count == 0){
  105. //删除商品核销信息表
  106. M('lionfish_comshop_goods_salesroombase')->where( array('goods_id' => $goods_id) )->delete();
  107. //更新商品为无核销状态
  108. M('lionfish_comshop_good_common')->where( array('goods_id' => $goods_id) )->save(array('is_only_hexiao'=>0));
  109. }
  110. }
  111. }
  112. }
  113. }
  114. }
  115. ?>