|
@@ -162,30 +162,6 @@ class Order extends Controller
|
|
|
$this->data = $data;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 订单备注
|
|
|
- * @auth true
|
|
|
- * @throws \think\Exception
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- * @throws \think\exception\PDOException
|
|
|
- */
|
|
|
- public function order_remark()
|
|
|
- {
|
|
|
- $id = $this->app->request->get('id');
|
|
|
- $this->assign('id', $id);
|
|
|
- $post = $this->app->request->post();
|
|
|
- if (isset($post['id']) && $post['id']) {
|
|
|
- Db::name($this->table)->where('id', $post['id'])->update(['mark' => $post['remark']]);
|
|
|
- $this->success('编辑成功!');
|
|
|
- } else {
|
|
|
- $this->_form($this->table, 'order_remark');
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 订单详情页
|
|
|
*/
|
|
@@ -194,271 +170,5 @@ class Order extends Controller
|
|
|
$this->_form($this->table);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 订单记录
|
|
|
- * @auth true
|
|
|
- * @throws \think\Exception
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- * @throws \think\exception\PDOException
|
|
|
- */
|
|
|
- public function order_status()
|
|
|
- {
|
|
|
- $id = $this->app->request->get('id');
|
|
|
- $this->assign('id', $id);
|
|
|
- $post = $this->app->request->post();
|
|
|
- if (isset($post['id']) && $post['id']) {
|
|
|
- Db::name($this->table)->where('id', $post['id'])->update(['remark' => $post['remark']]);
|
|
|
- $this->success('编辑成功!');
|
|
|
- } else {
|
|
|
- $this->_form($this->table);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 立即退款
|
|
|
- * @auth true
|
|
|
- * @throws \think\Exception
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- * @throws \think\exception\PDOException
|
|
|
- */
|
|
|
- public function order_refund()
|
|
|
- {
|
|
|
- $id = $this->app->request->get('id');
|
|
|
- $this->assign('id', $id);
|
|
|
- $post = $this->app->request->post();
|
|
|
- if (isset($post['id']) && $post['id']) {
|
|
|
- $order_info = Db::name($this->table)->where('id', $post['id'])->find();
|
|
|
- if($post['amount'] < 0 || $post['amount'] > $order_info['price_total']){
|
|
|
- $this->error('退款金额错误');
|
|
|
- }
|
|
|
- $refund_success = 0;
|
|
|
- $refund_info = Db::name('store_order_refund')->where('order_no', $order_info['order_no'])->find();
|
|
|
- if($order_info['pay_type'] == 1){ //微信退款
|
|
|
- $app = Factory::payment(config('app.wx_pay'));
|
|
|
- $result = $app->refund->byOutTradeNumber($order_info['pay_no'], $refund_info['refund_no'],$order_info['price_total']*100, $post['amount']*100, [
|
|
|
- // 可在此处传入其他参数,详细参数见微信支付文档
|
|
|
- 'refund_desc' => $refund_info['reason'],
|
|
|
- ]);
|
|
|
- if($result['return_code']=='SUCCESS' && $result['result_code']=='SUCCESS'){
|
|
|
- $refund_success = 1;
|
|
|
- }
|
|
|
- }elseif($order_info['pay_type'] == 2){
|
|
|
- $result = Alipay::ali_refund($order_info['pay_no'],$post['amount']);
|
|
|
- if($result){
|
|
|
- $refund_success = 1;
|
|
|
- }
|
|
|
- }else{ //余额退款
|
|
|
- $balance_data = array(
|
|
|
- 'amount' => $post['amount'],
|
|
|
- 'user_id' => $order_info['user_id'],
|
|
|
- 'user_type' => 1,
|
|
|
- 'get_type' => 4,
|
|
|
- 'order_id' => $order_info['id'],
|
|
|
- 'status' => 1
|
|
|
- );
|
|
|
- Db::name('store_balance_list')->insert($balance_data);
|
|
|
- Db::name('store_member')->where('id',$order_info['user_id'])->setInc('balance',$refund_info['amount']);
|
|
|
- $refund_success = 1;
|
|
|
- }
|
|
|
- if($refund_success == 1){
|
|
|
- Db::name('store_order_refund')->where('order_no',$order_info['order_no'])->update(array('status'=>1,'intervene_remark'=>$post['intervene_remark'],'dispose_at'=>date('Y-m-d H:i:s'),'amount'=>$post['amount']));
|
|
|
- //更改退款状态
|
|
|
- Db::name('store_order')->where('id',$id)->update(array('refund_state'=>2,'status'=>7,'refund_intervene'=>2,'refund_price'=>$post['amount']));
|
|
|
- //部分退款的剩下的给工人
|
|
|
- $residue_amount = $order_info['price_total'] - $post['amount'];
|
|
|
- if($residue_amount){
|
|
|
- //给接单端发送余额
|
|
|
- $balance_info = Db::name('store_balance_list')->where('user_id','>',0)->where('order_id',$id)->where('user_type',2)->where('status',0)->find();
|
|
|
- if($balance_info){
|
|
|
- //更改服务人员可拿的余额
|
|
|
- $balance_amount = sprintf("%.2f",$residue_amount * $order_info['worker_ratio'] / 100);
|
|
|
- Db::name('store_balance_list')->where('id',$balance_info['id'])->update(array('status'=>1,'amount'=>$balance_amount));
|
|
|
- Db::name('store_worker')->where('id',$balance_info['user_id'])->setInc('balance',$balance_amount);
|
|
|
- Db::name('store_worker')->where('id',$balance_info['user_id'])->setInc('balance_all',$balance_amount);
|
|
|
- }
|
|
|
- }
|
|
|
- $this->success('退款成功');
|
|
|
- }else{
|
|
|
- $this->error('退款失败');
|
|
|
- }
|
|
|
- } else {
|
|
|
- $this->_form($this->table, 'order_rufund');
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 不退款
|
|
|
- * @auth true
|
|
|
- * @throws \think\Exception
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- * @throws \think\exception\PDOException
|
|
|
- */
|
|
|
- public function order_no_refund()
|
|
|
- {
|
|
|
- $id = $this->app->request->get('id');
|
|
|
- $this->assign('id', $id);
|
|
|
- $post = $this->app->request->post();
|
|
|
- if (isset($post['id']) && $post['id']) {
|
|
|
-
|
|
|
- $order=Db::table('store_order')->where('id',$post['id'])->find();
|
|
|
-
|
|
|
- Db::name('store_order')->where('id', $post['id'])->update(['refund_state' => 3,'refund_intervene'=>2]);
|
|
|
- Db::name('store_order_refund')->where('order_no', $order['order_no'])
|
|
|
- ->update(['status' => 2,'intervene_remark'=>$post['intervene_remark'],'dispose_at'=>date('Y-m-d H:i:s')]);
|
|
|
-
|
|
|
- $this->success('拒绝成功!');
|
|
|
- } else {
|
|
|
- $this->_form($this->table, 'order_no_rufund');
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- /**
|
|
|
- * 处理投诉
|
|
|
- * @auth true
|
|
|
- * @throws \think\Exception
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- * @throws \think\exception\PDOException
|
|
|
- */
|
|
|
- public function dispose_complain()
|
|
|
- {
|
|
|
- $id = $this->app->request->get('id');
|
|
|
- $dispose_status = $this->app->request->get('dispose_status');
|
|
|
- $this->assign('id', $id);
|
|
|
- $this->assign('dispose_status', $dispose_status);
|
|
|
- $post = $this->app->request->post();
|
|
|
- if (isset($post['id']) && $post['id']) {
|
|
|
- $order_no = Db::name('store_order')->where('id',$id)->value('order_no');
|
|
|
- Db::name('store_complain')->where('order_no',$order_no)->update(array('result_info'=>$post['result_info'],'is_dispose'=>1,'dispose_at'=>date('Y-m-d H:i:s'),'dispose_status'=>$dispose_status));
|
|
|
- Db::name('store_order')->where('id',$id)->update(array('complain_status'=>2));
|
|
|
- $this->success('提交成功');
|
|
|
- }else{
|
|
|
- $this->_form($this->table, 'dispose_complain');
|
|
|
- }
|
|
|
- }
|
|
|
- /**
|
|
|
- * 修改时间
|
|
|
- * @auth true
|
|
|
- * @throws \think\Exception
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- * @throws \think\exception\PDOException
|
|
|
- */
|
|
|
- public function update_time()
|
|
|
- {
|
|
|
- $id = $this->app->request->get('id');
|
|
|
- $this->assign('id', $id);
|
|
|
- $post = $this->app->request->post();
|
|
|
- if (isset($post['id']) && $post['id']) {
|
|
|
- $order_info = Db::name('store_order')->field('id,order_no,appoint_time')->where('id',$id)->where('status',1)->where('work_status','in',[0,1])->find();
|
|
|
- if(empty($order_info)){
|
|
|
- $this->error('订单信息有误');
|
|
|
- }
|
|
|
- $post['appoint_time'] = date('Y-m-d H:00:00',strtotime($post['appoint_time']));
|
|
|
- if($post['appoint_time'] == $order_info['appoint_time']){
|
|
|
- $this->error('修改后的时间与服务时间一致,无需修改');
|
|
|
- }
|
|
|
- $res = update_appoint_time($order_info['order_no'],1,$post['appoint_time']);
|
|
|
- if($res['code']){
|
|
|
- $this->success('修改成功');
|
|
|
- }else{
|
|
|
- $this->error($res['msg']);
|
|
|
- }
|
|
|
- } else {
|
|
|
- $this->_form($this->table, 'update_time');
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- /**
|
|
|
- * 挂起订单
|
|
|
- * @auth true
|
|
|
- * @throws \think\Exception
|
|
|
- * @throws \think\exception\PDOException
|
|
|
- */
|
|
|
- public function hang_up()
|
|
|
- {
|
|
|
- //给用户发短信通知
|
|
|
- $id = $_POST['id'];
|
|
|
- $user_id = Db::name($this->table)->where('id',$id)->value('user_id');
|
|
|
- $phone = Db::name('store_member')->where('id',$user_id)->value('phone');
|
|
|
- short_note($phone);
|
|
|
- $this->_save($this->table, ['is_hang_up' => '1','apply_hang_up'=>0]);
|
|
|
- }
|
|
|
- public function export(){
|
|
|
- $data = $this->byWhere(2)->field('a.*,b.name,b.phone')->order('id desc')->select();
|
|
|
- foreach ($data as &$vo){
|
|
|
- //服务标题
|
|
|
- $vo['serve_title'] = Db::name('store_serve')->where('id',$vo['serve_id'])->value('title');
|
|
|
- //配件
|
|
|
- $vo['parts_title'] = '--';
|
|
|
- if($vo['parts_id']){
|
|
|
- $vo['parts_title'] = Db::name('store_serve_parts')->where('id',$vo['parts_id'])->value('title');
|
|
|
- }
|
|
|
- //分成信息
|
|
|
- $vo['worker_serve_amount'] = 0;
|
|
|
- $vo['worker_parts_amount'] = 0;
|
|
|
- $vo['agency_amount'] = 0;
|
|
|
- $vo['agency_parts_amount'] = 0;
|
|
|
- $vo['extend_amount'] = 0;
|
|
|
- if($vo['status'] > 0){
|
|
|
- $vo['worker_serve_amount'] = sprintf("%.2f",($vo['price_total'] - $vo['price_parts']) * $vo['worker_ratio']/100);
|
|
|
- $vo['worker_parts_amount'] = sprintf("%.2f",$vo['price_parts'] * $vo['worker_parts_ratio']/100);
|
|
|
- $vo['agency_amount'] = sprintf("%.2f",($vo['price_total'] - $vo['price_parts']) * $vo['agency_ratio']/100);
|
|
|
- $vo['agency_parts_amount'] = sprintf("%.2f",$vo['price_parts'] * $vo['agency_parts_ratio']/100);
|
|
|
- if($vo['puser_id']){
|
|
|
- $vo['extend_amount'] = sprintf("%.2f",($vo['price_total'] - $vo['price_parts']) * $vo['extend_ratio']/100);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- $field=array(
|
|
|
- 'A' => array('name', '下单人姓名'),
|
|
|
- 'B' => array('phone', '下单人手机号'),
|
|
|
- 'C' => array('order_no', '订单编号'),
|
|
|
- 'D' => array('price_goods', '订单金额(元)'),
|
|
|
- 'E' => array('price_total', '支付金额(元)'),
|
|
|
- 'F' => array('serve_title', '服务名称'),
|
|
|
- 'G' => array('parts_title', '配件名称'),
|
|
|
- 'H' => array('worker_serve_amount', '工程师服务佣金(元)'),
|
|
|
- 'I' => array('worker_parts_amount', '工程师配件佣金(元)'),
|
|
|
- 'J' => array('agency_amount', '代理服务佣金(元)'),
|
|
|
- 'K' => array('agency_parts_amount', '代理配件佣金(元)'),
|
|
|
- 'L' => array('extend_amount', '推广员佣金(元)'),
|
|
|
- 'M' => array('create_at', '下单时间'),
|
|
|
- );
|
|
|
- $this->phpExcelList($field,$data,'订单列表');
|
|
|
- }
|
|
|
-
|
|
|
- public function phpExcelList($field=[],$list=[],$title='文件'){
|
|
|
- $PHPExcel=new \PHPExcel();
|
|
|
- $PHPSheet=$PHPExcel->getActiveSheet();
|
|
|
- $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称
|
|
|
- foreach($list as $key=>$value)
|
|
|
- {
|
|
|
- foreach($field as $k=>$v){
|
|
|
- if($key == 0){
|
|
|
- $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]);
|
|
|
- }
|
|
|
- $i=$key+2;
|
|
|
- $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件,
|
|
|
- // Redirect output to a client’s web browser (Excel5)
|
|
|
- header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格
|
|
|
- header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称
|
|
|
- header('Cache-Control: max-age=0'); //禁止缓存
|
|
|
- $PHPWriter->save("php://output"); //输出到浏览器
|
|
|
- }
|
|
|
|
|
|
}
|