CommonorderModel.class.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Seller\Model;
  10. class CommonorderModel{
  11. //TODO....设置售后期的情况下进行确认收货,跟系统自动结算两个方法
  12. /**
  13. 获取一个订单中,商品的数量,
  14. **/
  15. public function get_order_goods_quantity( $order_id,$order_goods_id=0)
  16. {
  17. $where = "";
  18. if( !empty($order_goods_id) && $order_goods_id >0 )
  19. {
  20. $where .= " and order_goods_id={$order_goods_id} ";
  21. }
  22. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  23. //原来有的数量
  24. $total_quantity = M('lionfish_comshop_order_goods')->where( "order_id ={$order_id} {$where}" )->sum('quantity');
  25. $total_quantity = empty($total_quantity) ? 0 : $total_quantity;
  26. var_dump($total_quantity);
  27. $refund_quantity = $this->refund_order_goods_quantity( $order_id,$order_goods_id,$uniacid);
  28. $surplus_quantity = $total_quantity - $refund_quantity;
  29. if($order_info['delivery'] == 'hexiao'){
  30. $used_quantity = D('Home/Salesroom')->get_hexiao_order_goods_used_quantity($order_id,$order_goods_id);
  31. $surplus_quantity = $surplus_quantity - $used_quantity;
  32. }
  33. return $surplus_quantity;
  34. }
  35. /**
  36. 已经退掉的订单商品数量
  37. **/
  38. public function refund_order_goods_quantity( $order_id,$order_goods_id=0 )
  39. {
  40. $where = "";
  41. if( !empty($order_goods_id) && $order_goods_id >0 )
  42. {
  43. $where .= " and order_goods_id={$order_goods_id} ";
  44. }
  45. $refund_quantity = M('lionfish_comshop_order_goods_refund')->where("order_id ={$order_id} {$where}")->sum('real_refund_quantity');
  46. $refund_quantity = empty($refund_quantity) ? 0 : $refund_quantity;
  47. return $refund_quantity;
  48. }
  49. /**
  50. 该笔子订单已经退款了多少钱
  51. **/
  52. public function get_order_goods_refund_money( $order_id,$order_goods_id )
  53. {
  54. $where = "";
  55. if( !empty($order_goods_id) && $order_goods_id >0 )
  56. {
  57. $where .= " and order_goods_id={$order_goods_id} ";
  58. }
  59. $refund_money = M('lionfish_comshop_order_goods_refund')->where( "order_id ={$order_id} {$where}" )->sum('money');
  60. $refund_money = empty($refund_money) ? 0 : $refund_money;
  61. return $refund_money;
  62. }
  63. /**
  64. 获取订单商品支付的金额公共方法
  65. **/
  66. public function get_order_goods_paymoney( $order_goods_id )
  67. {
  68. $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id) )->find();
  69. if( empty($order_goods_info) )
  70. {
  71. return 0;
  72. }else{
  73. $pay_free = $order_goods_info['total'] + $order_goods_info['shipping_fare']-$order_goods_info['voucher_credit']-$order_goods_info['fullreduction_money']-$order_goods_info['score_for_money'];
  74. $pay_free = round($pay_free, 2);
  75. $order_info = M('lionfish_comshop_order')->field('type')->where( array('order_id' => $order_goods_info['order_id']) )->find();
  76. if( $order_info['type'] == 'integral' )
  77. {
  78. $pay_free = round($order_goods_info['shipping_fare'], 2);
  79. }
  80. return $pay_free;
  81. }
  82. }
  83. /**
  84. 获取订单金额--公共方法
  85. @auth fish
  86. **/
  87. public function get_order_paymoney( $order_id )
  88. {
  89. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  90. if( empty($order_info) )
  91. {
  92. return 0;
  93. }else{
  94. $pay_free = $order_info['total'] -$order_info['voucher_credit']-$order_info['fullreduction_money']-$order_info['score_for_money'];
  95. if( $order_info['type'] != 'integral' )
  96. {
  97. if($order_info['is_free_shipping_fare'] == 0 ){
  98. $pay_free += $order_info['shipping_fare'];
  99. }
  100. }
  101. $pay_free = round($pay_free, 2);
  102. return $pay_free;
  103. }
  104. }
  105. /**
  106. *
  107. * 获取订单已经退款了多少钱
  108. */
  109. public function order_refund_totalmoney( $order_id )
  110. {
  111. $total_money = M('lionfish_comshop_order_goods_refund')->where( array('order_id' =>$order_id ) )->sum('money');
  112. if( empty($total_money) )
  113. {
  114. $total_money = 0;
  115. }
  116. return $total_money;
  117. }
  118. /**
  119. * 获取订单商品 购买支付时,抵扣用了多少积分
  120. */
  121. public function get_order_goods_buyscore($order_id, $order_goods_id)
  122. {
  123. $integral_flow_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_id, 'order_goods_id' =>$order_goods_id,'type' => 'orderbuy' ) )->find();
  124. if( empty($integral_flow_info) )
  125. {
  126. return 0;
  127. }else{
  128. return $integral_flow_info['score'];
  129. }
  130. }
  131. /**
  132. * 退款积分
  133. */
  134. public function refund_order_goods_intrgral( $order_id, $order_goods_id ,$score )
  135. {
  136. $in_data = array();
  137. $in_data['uniacid'] = 0;
  138. $in_data['order_goods_id'] = $order_goods_id;
  139. $in_data['order_id'] = $order_id;
  140. $in_data['refund_score'] = $score;
  141. $in_data['addtime'] = time();
  142. $res = M('lionfish_comshop_order_goods_refund_intrgral')->add($in_data);
  143. }
  144. /**
  145. 退款整笔订单
  146. @auth lionfish
  147. @param is_back_buyscore 是否退积分,0否,1 是
  148. mail 353399459@qq.com
  149. time:2020-03-07
  150. **/
  151. public function refund_one_order( $order_id ,$is_back_buyscore = 0)
  152. {
  153. $_GPC = I('request.');
  154. $order_goods_list = M('lionfish_comshop_order_goods')->field('order_goods_id,quantity,shipping_fare,fenbi_li')->where( array('order_id' => $order_id , 'is_refund_state' => 0) )->select();
  155. if( !empty($order_goods_list) )
  156. {
  157. foreach( $order_goods_list as $val)
  158. {
  159. $order_goods_id = $val['order_goods_id'];
  160. $refund_shipping_fare = 0;
  161. if( $is_back_buyscore == 0)
  162. {
  163. $this->refund_order_goods_intrgral( $order_id, $order_goods_id ,0 );
  164. }else if($is_back_buyscore == 1){
  165. $integral_flow_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_id, 'order_goods_id' =>$order_goods_id,'type' => 'orderbuy' ) )->find();
  166. if( !empty($integral_flow_info) )
  167. {
  168. $has_refflow_score = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_id, 'order_goods_id' =>$order_goods_id,'type' => 'refundorder' ) )->sum('score');
  169. if( !empty($has_refflow_score) && $has_refflow_score > 0 )
  170. {
  171. $integral_flow_info['score'] -= $has_refflow_score;
  172. if($integral_flow_info['score'] < 0)
  173. {
  174. $integral_flow_info['score'] =0;
  175. }
  176. }
  177. $this->refund_order_goods_intrgral( $order_id, $order_goods_id ,$integral_flow_info['score'] );
  178. }
  179. }else if( $is_back_buyscore == 2)//退运费
  180. {
  181. $has_refund_shipping_fare = M('lionfish_comshop_order_goods_refund')->where( array('order_goods_id' => $val['order_goods_id'] ) )->sum('refund_shipping_fare');
  182. $refund_shipping_fare = $val['shipping_fare']-$has_refund_shipping_fare;
  183. }
  184. $is_has_refund_deliveryfree = D('Home/Front')->get_config_by_name('is_has_refund_deliveryfree');
  185. $is_has_refund_deliveryfree = !isset($is_has_refund_deliveryfree) || $is_has_refund_deliveryfree == 1 ? 1:0;
  186. if($is_has_refund_deliveryfree == 0){//不退配送费
  187. $refund_shipping_fare = $val['shipping_fare'];
  188. }
  189. $pay_total_money = $this->get_order_goods_paymoney( $order_goods_id );
  190. $has_refund_money = $this->get_order_goods_refund_money( $order_id,$order_goods_id );
  191. $has_refund_quantity = $this->refund_order_goods_quantity( $order_id,$order_goods_id);
  192. $real_refund_quantity = $val['quantity']- $has_refund_quantity;
  193. $refund_quantity = $real_refund_quantity - $has_refund_quantity;
  194. //$refund_money = round($pay_total_money - $has_refund_money - $val['shipping_fare'],2);
  195. $refund_money_sum = isset($_GPC['refund_money']) && $_GPC['refund_money'] >0 ? floatval($_GPC['refund_money']) : 0;
  196. $refund_money = $refund_money_sum * $val['fenbi_li'];
  197. $is_back_sellcount = 1;
  198. $this->ins_order_goods_refund($order_id, $order_goods_id,$pay_total_money,$real_refund_quantity, $refund_quantity,$refund_money, $is_back_sellcount, $refund_shipping_fare);
  199. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id ) )->save( array('is_refund_state' => 1 ) );
  200. }
  201. }
  202. }
  203. /**
  204. 每日订单-商品购买记录每日销量
  205. **/
  206. public function inc_daygoods_buy( $goods_id, $quantity )
  207. {
  208. //begin
  209. $today_zero_time = strtotime( date('Y-m-d').' 00:00:00' );
  210. //$clear_goodsdaysales = S('clear_goodsdaysales');
  211. $clear_goodsdaysales = D('Home/Front')->get_config_by_name('clear_goodsdaysales');
  212. if( !isset($today_zero_time) || $clear_goodsdaysales != $today_zero_time )
  213. {
  214. D('Seller/Commonorder')->clear_goods_daysales();
  215. //S('clear_goodsdaysales', $today_zero_time );
  216. $config_data = array();
  217. $config_data['clear_goodsdaysales'] = $today_zero_time;
  218. D('Seller/Config')->update($config_data);
  219. }
  220. //end
  221. M('lionfish_comshop_goods')->where( array('id' => $goods_id ) )->setInc('day_salescount', $quantity);
  222. }
  223. /**
  224. 每日订单-商品退款每日销量
  225. **/
  226. public function dec_daygoods_refund( $goods_id, $quantity )
  227. {
  228. M('lionfish_comshop_goods')->where( array('id' => $goods_id ) )->setInc('day_salescount', -$quantity);
  229. }
  230. /**
  231. 清理商品 每日销量
  232. **/
  233. public function clear_goods_daysales()
  234. {
  235. M('lionfish_comshop_goods')->where( "1=1" )->save( array('day_salescount' => 0 ) );
  236. }
  237. /**
  238. 插入子订单退款
  239. * $refund_shipping_fare 退款运费
  240. **/
  241. public function ins_order_goods_refund($order_id, $order_goods_id,$pay_total_money,$real_refund_quantity, $refund_quantity,$refund_money, $is_back_sellcount, $refund_shipping_fare)
  242. {
  243. //计算需要抵扣多少佣金 ims_ lionfish_comshop_order
  244. $commiss_info = M('lionfish_community_head_commiss_order')->where( " order_id={$order_id} and order_goods_id={$order_goods_id} and type='orderbuy' " )->find();
  245. // lionfish_comshop_order_goods
  246. $order_goods_info = M('lionfish_comshop_order_goods')->where( " order_goods_id={$order_goods_id} " )->find();
  247. //order_status_id
  248. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  249. $now_begin_time = strtotime( date('Y-m-d'.' 00:00:00') );
  250. $now_end_time = $now_begin_time + 86400;
  251. //今日订单今日退款成功减去今日销量
  252. if( $order_info['date_added'] >= $now_begin_time && $order_info['date_added'] < $now_end_time )
  253. {
  254. $this->dec_daygoods_refund( $order_goods_info['goods_id'], $real_refund_quantity );
  255. }
  256. $refund_data = array();
  257. $refund_data['order_goods_id'] = $order_goods_id;
  258. $refund_data['order_id'] = $order_id;
  259. $refund_data['uniacid'] = 0;
  260. $refund_data['real_refund_quantity'] = $real_refund_quantity;
  261. $refund_data['quantity'] = $refund_quantity;
  262. $refund_data['money'] = $refund_money;
  263. $refund_data['refund_shipping_fare'] = $refund_shipping_fare;
  264. $refund_data['order_status_id'] = $order_info['order_status_id'];
  265. $refund_data['is_back_quantity'] = $is_back_sellcount;
  266. //--- 以下需要计算了 refundorder
  267. $refund_data['back_score_for_money'] = 0;//退还积分兑换商品的积分 orderbuy
  268. $refund_data['back_send_score'] = 0; //退还赠送积分 goodsbuy
  269. $refund_data['back_head_orderbuycommiss'] = 0; //退还团长佣金
  270. $refund_data['back_head_supplycommiss'] = 0; //退还供应商佣金
  271. $refund_data['back_head_commiss_1'] = 0; //退1级团长佣金
  272. $refund_data['back_head_commiss_2'] = 0; //退2级团长佣金
  273. $refund_data['back_head_commiss_3'] = 0; //退3级团长佣金
  274. $refund_data['back_member_commiss_1'] = 0; //退会员1级佣金
  275. $refund_data['back_member_commiss_2'] = 0; //退会员2级佣金
  276. $refund_data['back_member_commiss_3'] = 0; //退会员3级佣金
  277. $refund_data['addtime'] = time(); //添加时间
  278. if( !empty($commiss_info) && $commiss_info['state'] == 1 )
  279. {
  280. //已经结算了
  281. //INSERT
  282. $id = M('lionfish_comshop_order_goods_refund')->add( $refund_data );
  283. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id) )->setInc('has_refund_money', $refund_money );
  284. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id) )->setInc('has_refund_quantity', $real_refund_quantity );
  285. //has_refund_money
  286. return $id;
  287. }else{
  288. //未结算的
  289. $score_for_money_info = M('lionfish_comshop_member_integral_flow')->where( " order_id={$order_id} and order_goods_id={$order_goods_id} and type='orderbuy' " )->find();
  290. if( !empty($score_for_money_info) )
  291. {
  292. if( $refund_money > 0 && $pay_total_money > 0)
  293. {
  294. $refund_data['back_score_for_money'] = ($refund_money / $pay_total_money ) * $score_for_money_info['score'] ;
  295. }else{
  296. $refund_data['back_score_for_money'] = 0 ;
  297. }
  298. //$refund_money
  299. $refund_intrgral_info = M('lionfish_comshop_order_goods_refund_intrgral')->where( array('order_goods_id' =>$order_goods_id ,'order_id' => $order_id ) )->order('id desc')->find();
  300. if( !empty($refund_intrgral_info) )
  301. {
  302. $refund_data['back_score_for_money'] = $refund_intrgral_info['refund_score'];
  303. }
  304. //退回去给用户
  305. D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$refund_data['back_score_for_money'], 0 ,'退款'.$real_refund_quantity.'个商品,增加积分','refundorder', $order_info['order_id'] ,$order_goods_id );
  306. $send_score_info = M('lionfish_comshop_member_integral_flow')->where(" order_id={$order_id} and order_goods_id={$order_goods_id} and type='goodsbuy' ")->find();
  307. }
  308. if( !empty($send_score_info) )
  309. {
  310. $refund_data['back_send_score'] = intval( ($refund_money / $pay_total_money ) * $send_score_info['score'] );
  311. $refund_data['back_send_score'] = $refund_data['back_send_score'] <= 0 ? 0 : $refund_data['back_send_score'];
  312. //减去相应的分数,然后插入
  313. M('lionfish_comshop_member_integral_flow')->where( " order_id={$order_id} and type='goodsbuy' and order_goods_id={$order_goods_id} " )->setInc('score', -$refund_data['back_send_score']);
  314. }
  315. //$refund_data['back_head_orderbuycommiss'] = 0; //退还团长佣金
  316. $head_commisslist = M('lionfish_community_head_commiss_order')->where( " type in ('orderbuy','commiss') and order_id={$order_id} and order_goods_id={$order_goods_id} and state=0 " )->select();
  317. if( !empty($head_commisslist) )
  318. {
  319. foreach( $head_commisslist as $val )
  320. {
  321. if( $val['type'] == 'orderbuy' )
  322. {
  323. //$goods_shipping_fare =$real_refund_quantity * round( ($real_refund_quantity / $order_goods_info['quantity'] ) * $order_goods_info['shipping_fare'] , 2);
  324. $head_orderbuycommiss = round( ($refund_money / $pay_total_money ) * $val['money'] , 2);
  325. $head_orderbuycommiss = $head_orderbuycommiss <= 0 ? 0 : $head_orderbuycommiss;
  326. M('lionfish_community_head_commiss_order')->where( array('id' => $val['id'] ) )->setInc('money', -$head_orderbuycommiss);
  327. $refund_data['back_head_orderbuycommiss'] = $head_orderbuycommiss;
  328. }
  329. if( $val['type'] == 'commiss' )
  330. {
  331. $val['money'] = $val['money'] - $val['add_shipping_fare'];
  332. if( $val['level'] == 1 )
  333. {
  334. $head_levelcommiss = round( ($refund_money / $pay_total_money ) * $val['money'] , 2);
  335. $head_levelcommiss = $head_levelcommiss <= 0 ? 0 : $head_levelcommiss;
  336. M('lionfish_community_head_commiss_order')->where( "id=".$val['id'] )->setInc('money', -$head_levelcommiss);
  337. $refund_data['back_head_commiss_1'] = $head_levelcommiss;
  338. }
  339. if( $val['level'] == 2 )
  340. {
  341. $head_levelcommiss = round( ($refund_money / $pay_total_money ) * $val['money'] , 2);
  342. $head_levelcommiss = $head_levelcommiss <= 0 ? 0 : $head_levelcommiss;
  343. M('lionfish_community_head_commiss_order')->where( array('id' => $val['id'] ) )->setInc('money', -$head_levelcommiss);
  344. $refund_data['back_head_commiss_2'] = $head_levelcommiss;
  345. }
  346. if( $val['level'] == 3 )
  347. {
  348. $head_levelcommiss = round( ($refund_money / $pay_total_money ) * $val['money'] , 2);
  349. $head_levelcommiss = $head_levelcommiss <= 0 ? 0 : $head_levelcommiss;
  350. M('lionfish_community_head_commiss_order')->where( array('id' => $val['id'] ) )->setInc('money', -$head_levelcommiss);
  351. $refund_data['back_head_commiss_3'] = $head_levelcommiss;
  352. }
  353. }
  354. }
  355. }
  356. //back_head_supplycommiss ims_lionfish_supply_commiss_order ims_
  357. $supply_commisslist = M('lionfish_supply_commiss_order')->where( " order_id={$order_id} and order_goods_id={$order_goods_id} and state=0 " )->find();
  358. if( !empty($supply_commisslist) )
  359. {
  360. $supply_orderbuycommiss = round( ($refund_money / $pay_total_money ) * $supply_commisslist['total_money'] , 2);
  361. $supply_orderbuycommiss_money = round( ($refund_money / $pay_total_money ) * $supply_commisslist['money'] , 2);
  362. $supply_orderbuycommiss = $supply_orderbuycommiss <= 0 ? 0 : $supply_orderbuycommiss;
  363. $supply_orderbuycommiss_money = $supply_orderbuycommiss_money <= 0 ? 0 : $supply_orderbuycommiss_money;
  364. M('lionfish_supply_commiss_order')->where( array('id' =>$supply_commisslist['id'] ) )->setInc('money', -$supply_orderbuycommiss_money );
  365. M('lionfish_supply_commiss_order')->where( array('id' =>$supply_commisslist['id'] ) )->setInc('total_money', -$supply_orderbuycommiss );
  366. $refund_data['back_head_supplycommiss'] = $supply_orderbuycommiss;
  367. }
  368. //
  369. //$refund_data['back_member_commiss_1'] = 0; //退会员1级佣金
  370. //$refund_data['back_member_commiss_2'] = 0; //退会员2级佣金
  371. //$refund_data['back_member_commiss_3'] = 0; //退会员3级佣金
  372. $member_commisslist = M('lionfish_comshop_member_commiss_order')->where( " order_id={$order_id} and order_goods_id={$order_goods_id} and state=0 " )->select();
  373. if( !empty($member_commisslist) )
  374. {
  375. foreach( $member_commisslist as $val )
  376. {
  377. if( $val['level'] == 1 )
  378. {
  379. $member_levelcommiss = round( ($refund_money / $pay_total_money ) * $val['money'] , 2);
  380. $member_levelcommiss = $member_levelcommiss <= 0 ? 0 : $member_levelcommiss;
  381. M('lionfish_comshop_member_commiss_order')->where( array('id' => $val['id'] ) )->setInc('money', -$member_levelcommiss );
  382. $refund_data['back_member_commiss_1'] = $member_levelcommiss;
  383. }
  384. if( $val['level'] == 2 )
  385. {
  386. $member_levelcommiss = round( ($refund_money / $pay_total_money ) * $val['money'] , 2);
  387. $member_levelcommiss = $member_levelcommiss <= 0 ? 0 : $member_levelcommiss;
  388. M('lionfish_comshop_member_commiss_order')->where( array('id' => $val['id'] ) )->setInc('money', -$member_levelcommiss);
  389. $refund_data['back_member_commiss_2'] = $member_levelcommiss;
  390. }
  391. if( $val['level'] == 3 )
  392. {
  393. $member_levelcommiss = round( ($refund_money / $pay_total_money ) * $val['money'] , 2);
  394. $member_levelcommiss = $member_levelcommiss <= 0 ? 0 : $member_levelcommiss;
  395. M('lionfish_comshop_member_commiss_order')->where( array('id' => $val['id'] ) )->setInc('money', -$member_levelcommiss );
  396. $refund_data['back_member_commiss_3'] = $member_levelcommiss;
  397. }
  398. }
  399. }
  400. //INSERT
  401. $id = M('lionfish_comshop_order_goods_refund')->add( $refund_data );
  402. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id) )->setInc('has_refund_money', $refund_money );
  403. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id) )->setInc('has_refund_quantity', $real_refund_quantity );
  404. //has_refund_money
  405. return $id;
  406. }
  407. }
  408. /**
  409. 后台订单详情 部分商品退款操作,检测是否整单退款
  410. TODO....
  411. **/
  412. public function check_refund_order_goods_status($order_id, $order_goods_id, $refund_money,$is_back_sellcount,$real_refund_quantity, $refund_quantity,$is_refund_shippingfare, $ref_comment = '后台操作立即退款,')
  413. {
  414. $refund_total_quantity = M('lionfish_comshop_order_goods_refund')->where( "order_id={$order_id} and order_goods_id={$order_goods_id} " )->sum('quantity');
  415. $order_goods_info = M('lionfish_comshop_order_goods')->where( "order_goods_id={$order_goods_id} " )->find();
  416. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  417. if( $refund_total_quantity >= $order_goods_info['quantity'] || $order_goods_info['has_refund_money'] >= $order_goods_info['total'])
  418. {
  419. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id ) )->save( array('is_refund_state' => 1 ) );
  420. $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id ) )->select();
  421. $is_all_refund = true;
  422. foreach($order_goods_list as $val )
  423. {
  424. if($val['is_refund_state'] != 1)
  425. {
  426. $is_all_refund = false;
  427. }
  428. }
  429. if($is_all_refund)
  430. {
  431. $comment = $ref_comment.'退款金额:'.$refund_money.'元';
  432. if( $order_info['type'] == 'integral' )
  433. {
  434. if( $order_info['shipping_fare'] > 0 )
  435. {
  436. $comment = $ref_comment.'退款金额:'.$order_info['shipping_fare'].'元,积分:'.$order_info['total'];
  437. }else{
  438. $comment = $ref_comment.'退还积分:'.$order_info['total'];
  439. }
  440. }
  441. if($is_refund_shippingfare == 1)
  442. {
  443. //最后一次金额
  444. $shipping_fare = M('lionfish_comshop_order_goods_refund')->where( "order_id={$order_id} and order_goods_id={$order_goods_id} " )->order('id desc')->find();
  445. if(!empty($shipping_fare['refund_shipping_fare'])){
  446. $comment .= '. 退配送费:'.$shipping_fare['refund_shipping_fare'].'元';
  447. }
  448. }
  449. if($is_back_sellcount == 1)
  450. {
  451. $comment .= '. 退款商品数量:'.$real_refund_quantity.'. 退库存/扣销量:'.$refund_quantity;
  452. }else{
  453. $comment .= '. 退款商品数量:'.$real_refund_quantity.'. 不退库存/不扣销量';
  454. }
  455. $order_history = array();
  456. $order_history['uniacid'] = $_W['uniacid'];
  457. $order_history['order_id'] = $order_id;
  458. $order_history['order_status_id'] = 7;
  459. $order_history['notify'] = 0;
  460. $order_history['comment'] = $comment;
  461. $order_history['date_added'] = time();
  462. M('lionfish_comshop_order_history')->add( $order_history );
  463. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 7) );
  464. $is_print_admin_cancleorder = D('Home/Front')->get_config_by_name('is_print_admin_cancleorder');
  465. if( isset($is_print_admin_cancleorder) && $is_print_admin_cancleorder == 1 )
  466. {
  467. D('Seller/Printaction')->check_print_order($order_id,'后台操作取消订单');
  468. D('Seller/Printaction')->check_print_order2($order_id,'后台操作取消订单');
  469. }
  470. }
  471. }else{
  472. }
  473. }
  474. /**
  475. 整单退款,切割退款金额到子订单
  476. **/
  477. public function def_order_refund_togoods( $order_id, $refund_money,$free_tongji,$is_refund_shippingfare )
  478. {
  479. }
  480. }
  481. ?>