Пример #1
0
 public function action_create()
 {
     if (\Input::method() == 'POST') {
         $msg = ['msg' => '', 'errcode' => 0, 'status' => 'succ'];
         //检测必要的订单信息
         $data = \Input::post();
         //生成订单明细
         $details = [];
         foreach ($data['goods'] as $id) {
             $item = \Model_Trolley::find_one_by('goods_id', $id);
             array_push($details, $item->to_array());
         }
         $this->load_details($details);
         //生成优惠信息
         $this->load_preferential($data['coupons']);
         if (!$this->save($data)) {
             $msg = ['msg' => $this->result_message, 'errcode' => 20, 'status' => 'err'];
         }
         if (\Input::is_ajax()) {
             die(json_encode($msg));
         }
     }
     $params = ['title' => ''];
     $params['trolley_ids'] = [1, 2, 3];
     \View::set_global($params);
     $this->template->title = '创建订单';
     $this->template->content = \View::forge("{$this->theme}/create");
 }
Пример #2
0
 /**
  * 保存订单
  * @param $data 订单数据
  */
 protected function save($data)
 {
     if (!$this->order) {
         $this->order = \Model_Order::forge();
     }
     $this->order->set($data);
     if (!$this->order->order_no) {
         $this->order->order_no = $this->generate_order_no();
     }
     if (!$this->order->buyer_id) {
         $this->order->buyer_id = \Auth::check() ? \Auth::get_user()->id : 0;
     }
     if (!$this->order->from_id) {
         $this->order->from_id = \Session::get('seller', false) ? \Session::get('seller')->id : 0;
     }
     if (!$this->order->order_status) {
         $this->order->order_status = 'WAIT_PAYMENT';
     }
     $this->original_fee = $this->order->total_fee - $this->order->preferential_fee;
     //保存订单
     if (!$this->order->save()) {
         return false;
     }
     //发送下单成功模板消息
     $params = ['first' => ['value' => '订单支付成功', 'color' => '#D02090'], 'keyword1' => ['value' => $this->order->order_no, 'color' => '#D02090'], 'keyword2' => ['value' => $this->order->order_name, 'color' => '#D02090'], 'keyword3' => ['value' => $this->order->total_fee, 'color' => '#D02090'], 'remark' => ['value' => '', 'color' => '#D02090']];
     $this->sendMsgTemplate('tQ46mymM617VOKpNv6rbg5hBQpXIle8EC64n-ozbSSw', $params, '');
     //清理购物车
     foreach ($this->order->details as $item) {
         $trollery = \Model_Trolley::find_one_by('goods_id', $item->id);
         if ($trollery === null) {
             continue;
         }
         $trollery->delete();
     }
 }
Пример #3
0
 /**
  * 清空购物车
  */
 public function action_remove_all()
 {
     $count = \DB::delete(\Model_Trolley::table())->where('user_id', $this->user->id)->execute();
     if ($count > 0) {
         $msg = ['status' => 'succ', 'msg' => '', 'errcode' => 0];
     }
     return $this->response($msg, 200);
 }