InvoiceService.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace addons\TinyShop\services\order;
  3. use common\components\Service;
  4. use common\helpers\ArrayHelper;
  5. use addons\TinyShop\common\models\order\Invoice;
  6. use addons\TinyShop\common\models\order\Order;
  7. use yii\web\UnprocessableEntityHttpException;
  8. /**
  9. * Class InvoiceService
  10. * @package addons\TinyShop\services\order
  11. * @author jianyan74 <751393839@qq.com>
  12. */
  13. class InvoiceService extends Service
  14. {
  15. /**
  16. * @param Order $order
  17. * @param $invoice
  18. * @param $explain
  19. * @return Invoice
  20. * @throws UnprocessableEntityHttpException
  21. */
  22. public function create(Order $order, $invoice, $explain)
  23. {
  24. $model = new Invoice();
  25. $model->attributes = ArrayHelper::toArray($invoice);
  26. $model->merchant_id = $order->merchant_id;
  27. $model->order_id = $order->id;
  28. $model->order_sn = $order->order_sn;
  29. $model->tax_money = $order->tax_money;
  30. $model->explain = $explain;
  31. if (!$model->save()) {
  32. throw new UnprocessableEntityHttpException($this->getError($model));
  33. }
  34. return $model;
  35. }
  36. /**
  37. * @param $order_id
  38. * @return array|\yii\db\ActiveRecord|null
  39. */
  40. public function findByOrderId($order_id)
  41. {
  42. return Invoice::find()
  43. ->where(['order_id' => $order_id])
  44. ->one();
  45. }
  46. }
粤ICP备19079148号