示例#1
0
 public function contract($order_id, $step = null)
 {
     AuthPlugins::required($this, array('销售经理', '销售顾问'));
     $order_id = abs(intval($order_id));
     $order = Order::get_by_id($order_id);
     if (!$step) {
         $step = 'solution';
     }
     $smarty = parent::load('smarty');
     $smarty->assign('order', $order);
     switch ($step) {
         case 'solution':
             $solution_id = abs(intval($_GET['id']));
             if ($solution_id) {
                 /*
                  * 全部设为非选定方案
                  */
                 Solution::set_unchecked();
                 /*
                  * 选定某个方案
                  */
                 Solution::select($solution_id);
                 HttpRedirect::to('order/contract/' . $order_id . '/paper');
             } else {
                 $solutions = Solution::get_by_order($order_id);
                 if (!$solutions) {
                     $message = '您还没有为此订单添加方案, 请返回添加';
                     HTTPRedirect::flash_to('order/detail/' . $order_id, $message, $smarty);
                 }
                 $smarty->assign('page_title', '签约订单 - 选定方案 Step 1');
                 $smarty->display('contract/solution');
             }
             break;
         case 'paper':
             if (!Solution::get_checked($order_id)) {
                 $message = '您还没有选择方案, 请返回选择';
                 HTTPRedirect::flash_to('order/contract/' . $order_id . '/solution', $message, $smarty);
             }
             if ($this->is_post() || $_FILES) {
                 import('system/share/io/filesystem');
                 FileSystem::init();
                 $http_path = FileSystem::Upload($_FILES['paper_attachment'], false);
                 if (!FileSystem::$local_path) {
                     $message = '不支持的附件类型, 请检查';
                     HTTPRedirect::flash_to('order/detail/' . $order_id, $message, $smarty);
                 }
                 $order->paper_attachment = $http_path;
                 $order->save();
                 HTTPRedirect::flash_to('order/contract/' . $order_id . '/payment', '上传合同成功', $this->smarty);
             } else {
                 $smarty->assign('page_title', '签约订单 - 上传合同附件 Step 2');
                 $smarty->display('contract/paper');
             }
             break;
         case 'payment':
             if ($this->is_post()) {
                 /*
                  * 获取选定的订单方案
                  */
                 $solution = Solution::get_checked($order_id);
                 /*首付款*/
                 $first_pay = new Payment();
                 $first_pay->order_id = $order_id;
                 $first_pay->type = 'first';
                 $first_pay->price = abs(intval($_POST['deposit']));
                 $first_pay->invoice = abs(intval($_POST['invoice']));
                 $first_pay->public = abs(intval($_POST['pub']));
                 $first_pay->bank = trim(strip_tags($_POST['bank']));
                 $first_pay->is_payed = abs(intval($_POST['is_deposit']));
                 $first_pay->save();
                 /*二期款*/
                 $second_pay = new Payment();
                 $second_pay->order_id = $order_id;
                 $second_pay->type = 'second';
                 $second_pay->price = abs(intval($_POST['payment']));
                 $second_pay->invoice = abs(intval($_POST['invoice']));
                 $second_pay->public = abs(intval($_POST['pub']));
                 $second_pay->bank = trim(strip_tags($_POST['bank']));
                 $second_pay->is_payed = abs(intval($_POST['is_payment']));
                 $second_pay->save();
                 /*尾款*/
                 $last_pay = new Payment();
                 $last_pay->order_id = $order_id;
                 $last_pay->type = 'last';
                 $last_pay->price = abs(intval($_POST['last_pay']));
                 $last_pay->invoice = abs(intval($_POST['invoice']));
                 $last_pay->public = abs(intval($_POST['pub']));
                 $last_pay->bank = trim(strip_tags($_POST['bank']));
                 $last_pay->is_payed = abs(intval($_POST['is_last_pay']));
                 $last_pay->save();
                 $old_workflow = $order->Workflow->action;
                 $workflow = Workflow::get_by_alias('新增财务订单');
                 $order->Workflow = $workflow;
                 $order->save();
                 /*
                  * 在用户表中写入客户的登录信息
                  * 登录名为客户填写的名字加订单ID
                  * 密码为'MG-客服ID-订单号'
                  */
                 $user = new User();
                 $user->username = $order->Customer->name . $order->id;
                 $user->password = User::generate_password(sprintf('MG-%s-%s', $order->customer_service_id, $order->id));
                 $user->Role[0] = Role::get_by_alias('客户');
                 $user->save();
                 $order->Customer->CustomerUser = $user;
                 $order->Customer->save();
                 $message = '恭喜您签约订单成功, 目前订单已转入财务管理页面';
                 HTTPRedirect::flash_to('order/list/6', $message, $smarty);
             } else {
                 $smarty->assign('page_title', '签约订单 - 付款信息 Step 3');
                 $smarty->display('contract/payment');
             }
             break;
     }
 }