|
|
@@ -7,7 +7,7 @@ use app\common\controller\Api;
|
|
|
use app\common\model\ProductLists;
|
|
|
use app\common\model\ProductOrder;
|
|
|
use app\common\model\Synthesis as SynthesisModel;
|
|
|
-use fast\Action;
|
|
|
+use Exception;
|
|
|
use fast\Asset;
|
|
|
use fast\Http;
|
|
|
use think\Db;
|
|
|
@@ -45,11 +45,11 @@ class Synthesis extends Api
|
|
|
{
|
|
|
$id = $this->request->param('id', 0, 'intval');
|
|
|
if(empty($id)) $this->error(__("参数有误,无可用产品"));
|
|
|
+ $lan = $this->request->getLan();
|
|
|
//合成详情
|
|
|
- $synthesis = SynthesisModel::get($id);
|
|
|
+ $synthesis = SynthesisModel::getBySynthesis($id, $lan);
|
|
|
if (!empty($synthesis)) {
|
|
|
//条件一
|
|
|
- $lan = $this->request->getLan();
|
|
|
$material_one = $productLists->getBySynthesisProduct($synthesis->material_one, $lan);
|
|
|
$synthesis->material_one = $productOrder->getByOrderProductNum($material_one, $synthesis->material_one_num, $this->auth->id);
|
|
|
//条件二
|
|
|
@@ -60,13 +60,45 @@ class Synthesis extends Api
|
|
|
$synthesis->material_three = $productOrder->getByOrderProductNum($material_three, $synthesis->material_one_num, $this->auth->id);
|
|
|
}
|
|
|
$this->success('', $synthesis);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ /*
|
|
|
+ * 合成
|
|
|
+ */
|
|
|
+ public function create( ProductOrder $productOrder)
|
|
|
+ {
|
|
|
+ $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 {
|
|
|
+
|
|
|
+ // 合成订单
|
|
|
+ $productOrder->setSynthesisOrder($synthesis, $productList, $num, $this->auth->id);
|
|
|
+
|
|
|
+ // 添加新订单
|
|
|
+ dump( 11);die;
|
|
|
+
|
|
|
+ // 提交事务
|
|
|
+ Db::commit();
|
|
|
+ } catch (Exception $e) {
|
|
|
+ // 回滚事务
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage(), null, $e->getCode());
|
|
|
+ }
|
|
|
+ $this->success('ok');
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|