Sellerbill.php 12 KB

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