Esempio n. 1
0
 /**
  * @param $get
  * @param $post
  * @return array
  * @throws Exception
  */
 public function addSampleProduceOrder($get, $post)
 {
     $business_order_id = $get['id'];
     $business_order = BusinessOrder::findOneByPk($business_order_id);
     $sample_produce_order = new SampleProduceOrder();
     if ($post) {
         $sample_list = BusinessOrderSamples::find('business_order_id=?', $business_order_id)->all();
         if (empty($sample_list)) {
             throw new BizException('样品列表为空,您必须先添加样品');
         }
         $exception = Model::transaction(function () use($sample_produce_order, $post, $sample_list, $business_order) {
             $sample_produce_order->setValues($post);
             $sample_produce_order->save();
             $data = array();
             /** @var BusinessOrderSamples $sm */
             foreach ($sample_list as $sm) {
                 $data[] = array('produce_order_id' => $sample_produce_order->id, 'sample_id' => $sm->sample_id, 'produce_num' => BusinessOrder::DEFAULT_PRODUCE_NUM, 'produce_request' => '无', 'produce_process_state' => 0, 'produce_employee_id' => 0);
             }
             SampleProduceOrderMapSamples::insertMany($data, false);
         });
         if ($exception) {
             dump($exception, 1);
             throw new BizException($exception);
         }
         return new Result('送样成功', true);
     }
     $sample_produce_order = new SampleProduceOrder();
     $customer = Customer::find('id = ?', $business_order->customer_id)->one();
     $current_contact = CustomerContact::find('id =?', $business_order->customer_contact_id)->one();
     return array('sample_produce_order' => $sample_produce_order, 'business_order' => $business_order, 'customer' => $customer, 'current_contact' => $current_contact);
 }