/** * 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!'); }
public function postRecoverEmptyGood($goodEmptyId) { $good_empty = GoodEmpty::find($goodEmptyId); $branch = Branch::find($good_empty->branch_id); $delivery = new Delivery(); $delivery->bn = date("YmdHis", time()) . $this->random(4, 1); $delivery->ship_name = $branch->name; $delivery->ship_addr = $branch->address; $delivery->ship_mobile = $branch->mobile; $delivery->t_begin = $this->__time(); $delivery->branch_id = $branch->id; $delivery->user_id = Auth::user()->id; $delivery->money = '0'; $delivery->status = '1'; $delivery->pay_status = '0'; $delivery->warehouse_id = Input::get('warehouse_id'); $delivery->type = '1'; $delivery->save(); $good_info = Good::find($good_empty->good_id); // 计算实际兑换量 // $empty_num = floor($good_empty->empty / $good_info->unit / $good_info->empty_unit); $empty = $empty_num * $good_info->unit; $good_info->empty = $good_info->empty + $empty; $good_info->store = $good_info->store - $empty; $good_info->save(); $product_info = Product::find(Input::get('item_id')); $product_info->empty = $product_info->empty + $empty; $product_info->store = $product_info->store - $empty; $product_info->save(); $delivery_item = new DeliveryItems(); $delivery_item->delivery_id = $delivery->id; $delivery_item->branch_id = $branch->id; $delivery_item->good_id = $good_info->id; $delivery_item->product_id = $product_info->id; $delivery_item->good_name = $good_info->name; $delivery_item->spec_info = ''; $delivery_item->number = $empty; $delivery_item->presentation = 0; $delivery_item->price = 0; $delivery_item->money = 0; $delivery_item->life_date = $product_info->life_date; $delivery_item->warehouse_id = $product_info->warehouse_id; $delivery_item->save(); // 日志 // $this->__goodLog($good_info->id, $product_info->id, 'empty'); $branch->last_visit_at = $branch->last_ship_at = $this->__time(); $branch->save(); $good_empty->delivery_id = $delivery->id; $good_empty->save(); return Redirect::to('picking/view/' . $delivery->id)->with('success', '兑换成功!'); }
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 . ')已完成!'); }