StoreOrderProfitsharing.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\common\model\store\order;
  3. use app\common\model\BaseModel;
  4. use app\common\model\system\merchant\Merchant;
  5. class StoreOrderProfitsharing extends BaseModel
  6. {
  7. const TYPE_NAME = ['order' => '订单支付', 'presell' => '尾款支付'];
  8. const STATUS_NAME = [0 => '待分账', 1 => '已分账', -1 => '已退款', -2 => '退款失败'];
  9. public static function tablePk(): string
  10. {
  11. return 'profitsharing_id';
  12. }
  13. public static function tableName(): string
  14. {
  15. return 'store_order_profitsharing';
  16. }
  17. public function getTypeNameAttr()
  18. {
  19. return self::TYPE_NAME[$this->getAttr('type')];
  20. }
  21. public function getStatusNameAttr()
  22. {
  23. return self::STATUS_NAME[$this->status];
  24. }
  25. public function order()
  26. {
  27. return $this->hasOne(StoreOrder::class, 'order_id', 'order_id');
  28. }
  29. public function merchant()
  30. {
  31. return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
  32. }
  33. public function getProfitsharingParmas()
  34. {
  35. return [
  36. 'transaction_id' => $this->transaction_id,
  37. 'sub_mchid' => $this->merchant->sub_mchid,
  38. 'out_order_no' => $this->profitsharing_sn,
  39. 'receivers' => [
  40. [
  41. 'amount' => bcsub($this->profitsharing_price, $this->profitsharing_mer_price, 2),
  42. 'body' => '订单分账',
  43. 'receiver_account' => systemConfig('wechat_service_merid'),
  44. ]
  45. ]
  46. ];
  47. }
  48. public function getProfitsharingFinishParmas()
  49. {
  50. return [
  51. 'sub_mchid' => $this->merchant->sub_mchid,
  52. 'transaction_id' => $this->order->transaction_id,
  53. 'out_order_no' => $this->profitsharing_sn,
  54. 'description' => '订单分账',
  55. ];
  56. }
  57. }