Sellerbill.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. * ============================================================================
  8. *
  9. * ============================================================================
  10. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  11. * 网站地址: https://www.valimart.net/
  12. * ----------------------------------------------------------------------------
  13. *
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Sellerbill extends BaseSeller {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/sellerbill.lang.php');
  21. }
  22. /**
  23. * 结算列表
  24. *
  25. */
  26. public function index() {
  27. $bill_model = model('bill');
  28. $condition = array();
  29. $condition[] = array('ob_store_id','=',session('store_id'));
  30. $ob_no = input('param.ob_no');
  31. if (preg_match('/^20\d{5,12}$/', $ob_no)) {
  32. $condition[] = array('ob_no','=',$ob_no);
  33. }
  34. $bill_state = intval(input('bill_state'));
  35. if ($bill_state) {
  36. $condition[] = array('ob_state','=',$bill_state);
  37. }
  38. $bill_list = $bill_model->getOrderbillList($condition, '*', 12, 'ob_state asc,ob_no asc');
  39. View::assign('bill_list', $bill_list);
  40. View::assign('show_page', $bill_model->page_info->render());
  41. /* 设置卖家当前菜单 */
  42. $this->setSellerCurMenu('Sellerbill');
  43. /* 设置卖家当前栏目 */
  44. $this->setSellerCurItem('seller_slide');
  45. return View::fetch($this->template_dir.'index');
  46. }
  47. /**
  48. * 查看结算单详细
  49. *
  50. */
  51. public function show_bill() {
  52. $ob_no = input('param.ob_no');
  53. if (!$ob_no) {
  54. $this->error(lang('param_error'));
  55. }
  56. $bill_model = model('bill');
  57. $bill_info = $bill_model->getOrderbillInfo(array('ob_no' => $ob_no,'ob_store_id'=>session('store_id')));
  58. if (!$bill_info) {
  59. $this->error(lang('param_error'));
  60. }
  61. $order_condition = array();
  62. $order_condition[] = array('ob_no','=',$ob_no);
  63. $order_condition[] = array('order_state','=',ORDER_STATE_SUCCESS);
  64. $order_condition[] = array('store_id','=',$bill_info['ob_store_id']);
  65. $query_start_date = input('get.query_start_date');
  66. $query_end_date = input('get.query_end_date');
  67. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  68. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  69. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  70. $end_unixtime = $if_end_date ? (strtotime($query_end_date)+86399) : null;
  71. if ($if_start_date) {
  72. if($if_start_date){
  73. $order_condition[] = array('finnshed_time','>=', $start_unixtime);
  74. }
  75. }
  76. if ($if_end_date) {
  77. if($if_end_date){
  78. $order_condition[] = array('finnshed_time','<=', $end_unixtime);
  79. }
  80. }
  81. $query_order_no = input('get.query_order_no');
  82. $type = input('param.type');
  83. if ($type == 'vrorder') {
  84. if (preg_match('/^\d{8,20}$/', $query_order_no)) {
  85. $order_condition[] = array('order_sn','=',$query_order_no);
  86. }
  87. $vrorder_model = model('vrorder');
  88. $order_list = $vrorder_model->getVrorderList($order_condition, 20,'SUM(ROUND(order_amount*commis_rate/100,2)) AS commis_amount,SUM(ROUND(refund_amount*commis_rate/100,2)) AS return_commis_amount,order_amount,refund_amount,order_sn,buyer_name,add_time,finnshed_time,order_id');
  89. foreach($order_list as $key => $val){
  90. if(!$val['order_id']){
  91. $order_list=array();
  92. break;
  93. }
  94. //分销佣金
  95. $inviter_info=Db::name('orderinviter')->where(array('orderinviter_order_id' => $key, 'orderinviter_valid' => 1, 'orderinviter_order_type' => 1))->field('SUM(orderinviter_money) AS ob_inviter_totals')->find();
  96. $order_list[$key]['inviter_amount']= ds_price_format($inviter_info['ob_inviter_totals']);
  97. }
  98. View::assign('order_list', $order_list);
  99. View::assign('show_page', $vrorder_model->page_info->render());
  100. $sub_tpl_name = 'show_vrorder_list';
  101. /* 设置卖家当前菜单 */
  102. $this->setSellerCurMenu('Sellerbill');
  103. /* 设置卖家当前栏目 */
  104. $this->setSellerCurItem('seller_slide');
  105. } elseif ($type == 'cost') {
  106. //店铺费用
  107. $storecost_model = model('storecost');
  108. $cost_condition = array();
  109. $cost_condition[] = array('storecost_store_id','=',$bill_info['ob_store_id']);
  110. $cost_condition[] = array('storecost_time','between',[$bill_info['ob_startdate'],$bill_info['ob_enddate']]);
  111. $store_cost_list = $storecost_model->getStorecostList($cost_condition, 20);
  112. //取得店铺名字
  113. $store_info = model('store')->getStoreInfoByID($bill_info['ob_store_id']);
  114. View::assign('cost_list', $store_cost_list);
  115. View::assign('store_info', $store_info);
  116. View::assign('show_page', $storecost_model->page_info->render());
  117. $sub_tpl_name = 'show_cost_list';
  118. /* 设置卖家当前菜单 */
  119. $this->setSellerCurMenu('Sellerbill');
  120. /* 设置卖家当前栏目 */
  121. $this->setSellerCurItem('seller_slide');
  122. } else {
  123. if (preg_match('/^\d{8,20}$/', $query_order_no)) {
  124. $order_condition[] = array('order_sn','=',$query_order_no);
  125. }
  126. //订单列表
  127. $order_model = model('order');
  128. $order_list = $order_model->getOrderList($order_condition, 20);
  129. //然后取订单商品佣金
  130. $order_id_array = array();
  131. if (is_array($order_list)) {
  132. foreach ($order_list as $order_info) {
  133. $order_id_array[] = $order_info['order_id'];
  134. }
  135. }
  136. $order_goods_condition = array();
  137. $order_goods_condition[]=array('order_id','in', $order_id_array);
  138. $field = 'SUM(ROUND(goods_pay_price*commis_rate/100,2)) as commis_amount,order_id';
  139. $commis_list = $order_model->getOrdergoodsList($order_goods_condition, $field, 0, null, '', 'order_id', 'order_id');
  140. foreach($commis_list as $key => $val){
  141. $return_commis_amount=0;
  142. $refund_info=Db::name('refundreturn')->alias('refundreturn')->join('ordergoods ordergoods', 'refundreturn.order_goods_id = ordergoods.rec_id')->where(array(array('refundreturn.order_id' ,'=', $key), array('refundreturn.refund_state' ,'=', 3), array('refundreturn.order_goods_id','>', 0)))->field('SUM(ROUND(refundreturn.refund_amount*ordergoods.commis_rate/100,2)) AS ob_commis_return_totals')->find();
  143. $return_commis_amount=$refund_info['ob_commis_return_totals'];
  144. $commis_list[$key]['return_commis_amount']=$return_commis_amount;
  145. //分销佣金
  146. $inviter_info=Db::name('orderinviter')->where(array('orderinviter_order_id' => $key, 'orderinviter_valid' => 1, 'orderinviter_order_type' => 0))->field('SUM(orderinviter_money) AS ob_inviter_totals')->find();
  147. $commis_list[$key]['inviter_amount']=$inviter_info['ob_inviter_totals'];
  148. //平台代金券
  149. $mallvoucher_info=Db::name('ordercommon')->where(array('order_id' => $key))->field('mallvoucher_price')->find();
  150. $commis_list[$key]['mall_voucher_totals']=number_format($mallvoucher_info['mallvoucher_price'], 2);
  151. }
  152. View::assign('commis_list', $commis_list);
  153. View::assign('order_list', $order_list);
  154. $order_list_page = Db::name('order')->where($order_condition)->paginate(['list_rows'=>20,'query' => request()->param()],false);
  155. View::assign('show_page', $order_list_page->render());
  156. $sub_tpl_name = 'show_order_list';
  157. /* 设置卖家当前菜单 */
  158. $this->setSellerCurMenu('Sellerbill');
  159. /* 设置卖家当前栏目 */
  160. $this->setSellerCurItem('seller_slide');
  161. }
  162. View::assign('bill_info', $bill_info);
  163. return View::fetch($this->template_dir.$sub_tpl_name);
  164. }
  165. /**
  166. * 打印结算单
  167. *
  168. */
  169. public function bill_print() {
  170. $ob_no = input('param.ob_no');
  171. if (!$ob_no) {
  172. $this->error(lang('param_error'));
  173. }
  174. $bill_model = model('bill');
  175. $condition = array();
  176. $condition[] = array('ob_no','=',$ob_no);
  177. $condition[] = array('ob_store_id','=',session('store_id'));
  178. $condition[] = array('ob_state','=',BILL_STATE_SUCCESS);
  179. $bill_info = $bill_model->getOrderbillInfo($condition);
  180. if (!$bill_info) {
  181. $this->error(lang('param_error'));
  182. }
  183. View::assign('bill_info', $bill_info);
  184. return View::fetch($this->template_dir.'bill_print');
  185. }
  186. /**
  187. * 店铺确认出账单
  188. *
  189. */
  190. public function confirm_bill() {
  191. $ob_no = input('param.ob_no');
  192. if (!$ob_no) {
  193. ds_json_encode(10001,lang('param_error'));
  194. }
  195. $bill_model = model('bill');
  196. $condition = array();
  197. $condition[] = array('ob_no','=',$ob_no);
  198. $condition[] = array('ob_store_id','=',session('store_id'));
  199. $condition[] = array('ob_state','=',BILL_STATE_CREATE);
  200. $bill_info=$bill_model->getOrderbillInfo($condition);
  201. if(!$bill_info){
  202. ds_json_encode(10001,lang('bill_is_not_exist'));
  203. }
  204. if(request()->isPost()){
  205. $update = $bill_model->editOrderbill(array('ob_state' => BILL_STATE_STORE_COFIRM,'ob_seller_content'=>input('post.ob_seller_content')), $condition);
  206. if ($update) {
  207. ds_json_encode(10000,lang('ds_common_op_succ'));
  208. } else {
  209. ds_json_encode(10001,lang('ds_common_op_fail'));
  210. }
  211. }else{
  212. return View::fetch($this->template_dir.'bill_confirm');
  213. }
  214. }
  215. /**
  216. * 用户中心右边,小导航
  217. *
  218. * @param string $menu_type 导航类型
  219. * @param string $menu_key 当前导航的menu_key
  220. * @return
  221. */
  222. function getSellerItemList() {
  223. $ob_no = input('param.ob_no');
  224. if (request()->action()=='index') {
  225. $menu_array = array(
  226. array(
  227. 'name' => 'list',
  228. 'text' => lang('physical_settlement'),
  229. 'url' => (string)url('Sellerbill/index')
  230. ),
  231. );
  232. }else if(request()->action()=='show_bill'){
  233. $menu_array = array(
  234. array(
  235. 'name' => 'order_list',
  236. 'text' => lang('order_list'),
  237. 'url' => (string)url('Sellerbill/show_bill', ['ob_no' => $ob_no])
  238. ),
  239. array(
  240. 'name' => 'vrorder_list',
  241. 'text' => lang('vrorder_list'),
  242. 'url' => (string)url('Sellerbill/show_bill', ['type'=>'vrorder','ob_no' => $ob_no])
  243. ),
  244. array(
  245. 'name' => 'cost_list',
  246. 'text' => lang('cost_list'),
  247. 'url' => (string)url('Sellerbill/show_bill', ['type'=>'cost','ob_no' => $ob_no])
  248. ),
  249. );
  250. }
  251. return $menu_array;
  252. }
  253. }
  254. ?>