Exemplo n.º 1
0
 /**
  * 生产单号
  */
 public static function generateOrderNo()
 {
     $last_order = SampleProduceOrder::find('create_time >= ?', strtotime(date('Y-m-01 00:00:00')))->order('create_time DESC')->one();
     $no = '00';
     if ($last_order) {
         $last_no = substr($last_order->order_no, -2);
         if ($last_no == 99) {
             throw new Exception('order no full');
         }
         $new_no = (int) $last_no + 1;
         $no = str_pad($new_no, 2, '0', STR_PAD_LEFT);
     }
     $no = 'S' . date('ym') . $no;
     return $no;
 }
 public function index($search)
 {
     $paginate = Paginate::instance();
     $query = SampleProduceOrder::find();
     if ($search['kw']) {
         $query->addWhere(Query::OP_AND, 'order_no', 'like', "%{$search['kw']}%");
     }
     if (strlen($search['produce_type'])) {
         $query->addWhere(Query::OP_AND, 'produce_type', '=', intval($search['produce_type']));
     }
     if (strlen($search['state'])) {
         $query->addWhere(Query::OP_AND, 'state', '=', intval($search['state']));
     }
     $order_list = $query->paginate($paginate);
     $def = SampleProduceOrder::meta()->getPropertiesDefine();
     return array('produce_type_options' => $def['produce_type']['options'], 'state_options' => $def['state']['options'], 'search' => $search, 'order_list' => $order_list, 'paginate' => $paginate);
 }
Exemplo n.º 3
0
 public function __construct($data = array())
 {
     parent::__construct($data);
     $this->setPropertiesDefine(array('customer_id' => array('display' => function (BusinessOrder $item) {
         return Customer::findOneByPk($item->customer_id)->company_alias_name;
     }, 'alias' => '公司简称'), 'customer_contact_id' => array('display' => function (BusinessOrder $item) {
         return CustomerContact::findOneByPk($item->customer_contact_id)->chinese_name;
     }, 'alias' => '联系人'), 'pay_type_id' => array('options' => function () {
         $tmp = PayType::find('state=?', PayType::STATE_ENABLED)->all(true);
         return array_combine(array_column($tmp, 'id'), array_column($tmp, 'name'));
     }, 'display' => function (self $item) {
         $tmp = PayType::findOneByPk($item->pay_type_id);
         if (!$tmp) {
             return '';
         }
         return $tmp->state == PayType::STATE_ENABLED ? $tmp->name : '<del>' . $tmp->name . '</del>';
     }), 'settle_currency_name' => array('getter' => function (BusinessOrder $item) {
         return $item->getPropertiesDefine('settle_currency')['options'][$item->settle_currency];
     }), 'sample_produce_order' => array('getter' => function (self $item) {
         return SampleProduceOrder::find('business_order_id=?', $item->id)->one();
     })));
 }