lan = $this->request->getLan(); } public function list(SynthesisModel $synthesis) { $list = $synthesis->alias('a') ->join("product_list b", "a.product_id = b.id", "left") ->field('a.id,a.title,a.start_time,a.end_time,b.thum as img_url') ->where('a.status', $synthesis::Normal)->where('a.to_lang', $this->lan) ->order('a.weigh desc') ->paginate($this->pageSize); $this->success('', $list); } /* * 合成详情 */ public function detail(ProductLists $productLists, ProductOrder $productOrder) { $id = $this->request->param('id', 0, 'intval'); if(empty($id)) $this->error(__("参数有误,无可用产品")); $lan = $this->request->getLan(); //合成详情 $synthesis = SynthesisModel::getBySynthesis($id, $lan); if (!empty($synthesis)) { //条件一 $material_one = $productLists->getBySynthesisProduct($synthesis->material_one, 1, $lan); $synthesis->material_one = $productOrder->getByOrderProductNum($material_one, $synthesis->material_one_num, $this->auth->id); //条件二 $material_two = $productLists->getBySynthesisProduct($synthesis->material_two, 2, $lan); $synthesis->material_two = $productOrder->getByOrderProductNum($material_two, $synthesis->material_two_num, $this->auth->id); //条件三 $material_three = $productLists->getBySynthesisProduct($synthesis->material_three, 2, $lan); $synthesis->material_three = $productOrder->getByOrderProductNum($material_three, $synthesis->material_three_num, $this->auth->id); } $this->success('', $synthesis); } /* * 合成 */ public function create(ProductOrder $productOrder, UserSynthesis $userSynthesis) { $id = $this->request->post('id', 0, 'intval'); $num = $this->request->post('num', 0, 'intval'); $productList= $this->request->param('product_list/a'); //选中产品 if(empty($id) || empty($num)) $this->error(__("参数有误,无可用产品")); //合成详情 $synthesis = SynthesisModel::get($id); if (empty($synthesis)) $this->error(__("合成活动不存在")); $time = time(); if ($synthesis->start_time > $time || $synthesis->end_time < $time)$this->error(__("合成活动已结束")); if ($synthesis->num + $num > $synthesis->stock)$this->error(__("库存不足")); Db::startTrans(); try { // 合成订单 $order_list = $productOrder->setSynthesisOrder($synthesis, $productList, $num, $this->auth->id); // 添加新订单 WelfareLoginc::setUserProductOrder($num, 0, $synthesis->id, 0, $synthesis->product_id, $this->auth->id, $productOrder::Synthesi); //合成记录 $userSynthesis::setUserSynthesisLog($this->auth->id, $id, $num, $order_list); $synthesis->num += $num; $synthesis->save(); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error($e->getMessage(), null, $e->getCode()); } $this->success('ok'); } }