Ejemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->info('Search Delivery Items Life Time');
     // 六十天提醒
     //
     $N_Time = date("Y-m-d", time());
     $L_Time = date("Y-m-d", time() + 60 * 3600 * 24);
     // 获取满足条件的货品
     //
     $Items = DeliveryItems::where('life_date', '>', $N_Time)->where('life_date', '<', $L_Time)->orderBy('delivery_id', 'desc')->get();
     // 初始化
     //
     $branch_ids = array();
     $delivery_ids = array();
     foreach ($Items as $Item) {
         // 条件过滤
         //
         if (!in_array($Item->delivery_id, $delivery_ids) && in_array($Item->branch_id, $branch_ids)) {
             continue;
         } else {
             if (!in_array($Item->delivery_id, $delivery_ids)) {
                 $delivery_ids[] = $Item->delivery_id;
             }
             if (!in_array($Item->branch_id, $branch_ids)) {
                 $branch_ids[] = $Item->branch_id;
             }
             $branch = Branch::find($Item->branch_id);
             $delivery = Delivery::find($Item->delivery_id);
             if ($branch && $delivery) {
                 $notice = new Notice();
                 $notice->user_id = $branch->user_id;
                 $notice->type = '5';
                 $notice->content = '客户(' . $branch->name . ')的出货单(' . $delivery->bn . ')中商品(' . $Item->good_name . ')' . date("Y-m-d", strtotime($Item->life_date)) . ' 过期!';
                 $notice->data = json_encode(array('branch_id' => $Item->branch_id, 'delivery_id' => $Item->delivery_id));
                 $notice->read = '0';
                 $notice->timeline = date("Y-m-d H:i:s", time());
                 $notice->save();
                 $this->info($notice->content);
             }
         }
     }
     $this->info('Done!');
 }
Ejemplo n.º 2
0
 /**
  *
  */
 public function actionCreate()
 {
     $model = new Delivery();
     if (isset($_POST['Delivery'])) {
         $model->attributes = $_POST['Delivery'];
         if ($model->save()) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('DeliveryModule.delivery', 'Record created!'));
             if (!isset($_POST['submit-type'])) {
                 $this->redirect(['update', 'id' => $model->id]);
             } else {
                 $this->redirect([$_POST['submit-type']]);
             }
         }
     }
     $criteria = new CDbCriteria();
     $criteria->select = new CDbExpression('MAX(position) as position');
     $max = $model->find($criteria);
     $model->position = $max->position + 1;
     $payments = Payment::model()->published()->findAll(['order' => 'position']);
     $this->render('create', ['model' => $model, 'payments' => $payments]);
 }
 /**
  * close a delivery
  *
  * @param $deliveryId
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postClose($deliveryId)
 {
     // if cant load
     if (!($delivery = Delivery::find($deliveryId))) {
         return Redirect::back()->with('errors', new MessageBag(['An error has occurred.']));
     }
     // if not allowed
     if (!$delivery->allowedToClose(Auth::user())) {
         return Redirect::back()->with('errors', new MessageBag(['You are not allowed to close the delivery.', 'It\'s got to be your delivery and having no orders']));
     }
     $delivery->close();
     $messages = new MessageBag();
     $messages->add('success', 'Successfully closed your delivery!');
     return Redirect::back()->with('messages', $messages);
 }
Ejemplo n.º 4
0
 public function postDone($PickingID)
 {
     $rules = array('real_bn' => 'required|unique:delivery');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('picking/done/' . $PickingID)->withErrors($validator)->withInput();
     }
     $delivery = Delivery::find($PickingID);
     $delivery->status = '3';
     $delivery->real_bn = Input::get('real_bn');
     $delivery->pay_status = Input::get('pay_status');
     $delivery->t_confirm = $this->__time();
     $delivery->save();
     // 增加销售记录 用于退换回收 2014.05.21
     $delivery_items = DeliveryItems::where('delivery_id', $delivery->id)->get();
     foreach ($delivery_items as $item) {
         $g = BranchGoodItems::where('good_id', $item->good_id)->where('branch_id', $item->branch_id)->first();
         if ($g) {
             $i = BranchGoodItems::find($g->id);
             $i->sell = $i->sell + $item->number;
             $i->save();
         } else {
             $i = new BranchGoodItems();
             $i->good_id = $item->good_id;
             $i->branch_id = $item->branch_id;
             $i->sell = $item->number;
             $i->save();
         }
     }
     return Redirect::to('picking')->with('success', '出货单(' . $delivery->bn . ')已完成!');
 }
 private function createNewOrder()
 {
     $deliveryId = $this->getRandomDeliveryId();
     $delivery = Delivery::find($deliveryId);
     Order::create(array('user_id' => $this->getRandomUserId(), 'dish_id' => $this->getRandomDishId($delivery->storeId), 'delivery_id' => $deliveryId));
 }