SalesroomModel.class.php 4.7 KB

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