payrecharge_update.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "wechat-api/ent/payrecharge"
  9. "wechat-api/ent/predicate"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/schema/field"
  13. )
  14. // PayRechargeUpdate is the builder for updating PayRecharge entities.
  15. type PayRechargeUpdate struct {
  16. config
  17. hooks []Hook
  18. mutation *PayRechargeMutation
  19. }
  20. // Where appends a list predicates to the PayRechargeUpdate builder.
  21. func (pru *PayRechargeUpdate) Where(ps ...predicate.PayRecharge) *PayRechargeUpdate {
  22. pru.mutation.Where(ps...)
  23. return pru
  24. }
  25. // SetUpdatedAt sets the "updated_at" field.
  26. func (pru *PayRechargeUpdate) SetUpdatedAt(t time.Time) *PayRechargeUpdate {
  27. pru.mutation.SetUpdatedAt(t)
  28. return pru
  29. }
  30. // SetDeletedAt sets the "deleted_at" field.
  31. func (pru *PayRechargeUpdate) SetDeletedAt(t time.Time) *PayRechargeUpdate {
  32. pru.mutation.SetDeletedAt(t)
  33. return pru
  34. }
  35. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  36. func (pru *PayRechargeUpdate) SetNillableDeletedAt(t *time.Time) *PayRechargeUpdate {
  37. if t != nil {
  38. pru.SetDeletedAt(*t)
  39. }
  40. return pru
  41. }
  42. // ClearDeletedAt clears the value of the "deleted_at" field.
  43. func (pru *PayRechargeUpdate) ClearDeletedAt() *PayRechargeUpdate {
  44. pru.mutation.ClearDeletedAt()
  45. return pru
  46. }
  47. // SetUserID sets the "user_id" field.
  48. func (pru *PayRechargeUpdate) SetUserID(s string) *PayRechargeUpdate {
  49. pru.mutation.SetUserID(s)
  50. return pru
  51. }
  52. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  53. func (pru *PayRechargeUpdate) SetNillableUserID(s *string) *PayRechargeUpdate {
  54. if s != nil {
  55. pru.SetUserID(*s)
  56. }
  57. return pru
  58. }
  59. // SetNumber sets the "number" field.
  60. func (pru *PayRechargeUpdate) SetNumber(f float32) *PayRechargeUpdate {
  61. pru.mutation.ResetNumber()
  62. pru.mutation.SetNumber(f)
  63. return pru
  64. }
  65. // SetNillableNumber sets the "number" field if the given value is not nil.
  66. func (pru *PayRechargeUpdate) SetNillableNumber(f *float32) *PayRechargeUpdate {
  67. if f != nil {
  68. pru.SetNumber(*f)
  69. }
  70. return pru
  71. }
  72. // AddNumber adds f to the "number" field.
  73. func (pru *PayRechargeUpdate) AddNumber(f float32) *PayRechargeUpdate {
  74. pru.mutation.AddNumber(f)
  75. return pru
  76. }
  77. // SetStatus sets the "status" field.
  78. func (pru *PayRechargeUpdate) SetStatus(i int) *PayRechargeUpdate {
  79. pru.mutation.ResetStatus()
  80. pru.mutation.SetStatus(i)
  81. return pru
  82. }
  83. // SetNillableStatus sets the "status" field if the given value is not nil.
  84. func (pru *PayRechargeUpdate) SetNillableStatus(i *int) *PayRechargeUpdate {
  85. if i != nil {
  86. pru.SetStatus(*i)
  87. }
  88. return pru
  89. }
  90. // AddStatus adds i to the "status" field.
  91. func (pru *PayRechargeUpdate) AddStatus(i int) *PayRechargeUpdate {
  92. pru.mutation.AddStatus(i)
  93. return pru
  94. }
  95. // ClearStatus clears the value of the "status" field.
  96. func (pru *PayRechargeUpdate) ClearStatus() *PayRechargeUpdate {
  97. pru.mutation.ClearStatus()
  98. return pru
  99. }
  100. // SetMoney sets the "money" field.
  101. func (pru *PayRechargeUpdate) SetMoney(f float32) *PayRechargeUpdate {
  102. pru.mutation.ResetMoney()
  103. pru.mutation.SetMoney(f)
  104. return pru
  105. }
  106. // SetNillableMoney sets the "money" field if the given value is not nil.
  107. func (pru *PayRechargeUpdate) SetNillableMoney(f *float32) *PayRechargeUpdate {
  108. if f != nil {
  109. pru.SetMoney(*f)
  110. }
  111. return pru
  112. }
  113. // AddMoney adds f to the "money" field.
  114. func (pru *PayRechargeUpdate) AddMoney(f float32) *PayRechargeUpdate {
  115. pru.mutation.AddMoney(f)
  116. return pru
  117. }
  118. // ClearMoney clears the value of the "money" field.
  119. func (pru *PayRechargeUpdate) ClearMoney() *PayRechargeUpdate {
  120. pru.mutation.ClearMoney()
  121. return pru
  122. }
  123. // SetOutTradeNo sets the "out_trade_no" field.
  124. func (pru *PayRechargeUpdate) SetOutTradeNo(s string) *PayRechargeUpdate {
  125. pru.mutation.SetOutTradeNo(s)
  126. return pru
  127. }
  128. // SetNillableOutTradeNo sets the "out_trade_no" field if the given value is not nil.
  129. func (pru *PayRechargeUpdate) SetNillableOutTradeNo(s *string) *PayRechargeUpdate {
  130. if s != nil {
  131. pru.SetOutTradeNo(*s)
  132. }
  133. return pru
  134. }
  135. // ClearOutTradeNo clears the value of the "out_trade_no" field.
  136. func (pru *PayRechargeUpdate) ClearOutTradeNo() *PayRechargeUpdate {
  137. pru.mutation.ClearOutTradeNo()
  138. return pru
  139. }
  140. // SetOrganizationID sets the "organization_id" field.
  141. func (pru *PayRechargeUpdate) SetOrganizationID(u uint64) *PayRechargeUpdate {
  142. pru.mutation.ResetOrganizationID()
  143. pru.mutation.SetOrganizationID(u)
  144. return pru
  145. }
  146. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  147. func (pru *PayRechargeUpdate) SetNillableOrganizationID(u *uint64) *PayRechargeUpdate {
  148. if u != nil {
  149. pru.SetOrganizationID(*u)
  150. }
  151. return pru
  152. }
  153. // AddOrganizationID adds u to the "organization_id" field.
  154. func (pru *PayRechargeUpdate) AddOrganizationID(u int64) *PayRechargeUpdate {
  155. pru.mutation.AddOrganizationID(u)
  156. return pru
  157. }
  158. // Mutation returns the PayRechargeMutation object of the builder.
  159. func (pru *PayRechargeUpdate) Mutation() *PayRechargeMutation {
  160. return pru.mutation
  161. }
  162. // Save executes the query and returns the number of nodes affected by the update operation.
  163. func (pru *PayRechargeUpdate) Save(ctx context.Context) (int, error) {
  164. if err := pru.defaults(); err != nil {
  165. return 0, err
  166. }
  167. return withHooks(ctx, pru.sqlSave, pru.mutation, pru.hooks)
  168. }
  169. // SaveX is like Save, but panics if an error occurs.
  170. func (pru *PayRechargeUpdate) SaveX(ctx context.Context) int {
  171. affected, err := pru.Save(ctx)
  172. if err != nil {
  173. panic(err)
  174. }
  175. return affected
  176. }
  177. // Exec executes the query.
  178. func (pru *PayRechargeUpdate) Exec(ctx context.Context) error {
  179. _, err := pru.Save(ctx)
  180. return err
  181. }
  182. // ExecX is like Exec, but panics if an error occurs.
  183. func (pru *PayRechargeUpdate) ExecX(ctx context.Context) {
  184. if err := pru.Exec(ctx); err != nil {
  185. panic(err)
  186. }
  187. }
  188. // defaults sets the default values of the builder before save.
  189. func (pru *PayRechargeUpdate) defaults() error {
  190. if _, ok := pru.mutation.UpdatedAt(); !ok {
  191. if payrecharge.UpdateDefaultUpdatedAt == nil {
  192. return fmt.Errorf("ent: uninitialized payrecharge.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  193. }
  194. v := payrecharge.UpdateDefaultUpdatedAt()
  195. pru.mutation.SetUpdatedAt(v)
  196. }
  197. return nil
  198. }
  199. // check runs all checks and user-defined validators on the builder.
  200. func (pru *PayRechargeUpdate) check() error {
  201. if v, ok := pru.mutation.UserID(); ok {
  202. if err := payrecharge.UserIDValidator(v); err != nil {
  203. return &ValidationError{Name: "user_id", err: fmt.Errorf(`ent: validator failed for field "PayRecharge.user_id": %w`, err)}
  204. }
  205. }
  206. if v, ok := pru.mutation.Status(); ok {
  207. if err := payrecharge.StatusValidator(v); err != nil {
  208. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "PayRecharge.status": %w`, err)}
  209. }
  210. }
  211. if v, ok := pru.mutation.OrganizationID(); ok {
  212. if err := payrecharge.OrganizationIDValidator(v); err != nil {
  213. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "PayRecharge.organization_id": %w`, err)}
  214. }
  215. }
  216. return nil
  217. }
  218. func (pru *PayRechargeUpdate) sqlSave(ctx context.Context) (n int, err error) {
  219. if err := pru.check(); err != nil {
  220. return n, err
  221. }
  222. _spec := sqlgraph.NewUpdateSpec(payrecharge.Table, payrecharge.Columns, sqlgraph.NewFieldSpec(payrecharge.FieldID, field.TypeUint64))
  223. if ps := pru.mutation.predicates; len(ps) > 0 {
  224. _spec.Predicate = func(selector *sql.Selector) {
  225. for i := range ps {
  226. ps[i](selector)
  227. }
  228. }
  229. }
  230. if value, ok := pru.mutation.UpdatedAt(); ok {
  231. _spec.SetField(payrecharge.FieldUpdatedAt, field.TypeTime, value)
  232. }
  233. if value, ok := pru.mutation.DeletedAt(); ok {
  234. _spec.SetField(payrecharge.FieldDeletedAt, field.TypeTime, value)
  235. }
  236. if pru.mutation.DeletedAtCleared() {
  237. _spec.ClearField(payrecharge.FieldDeletedAt, field.TypeTime)
  238. }
  239. if value, ok := pru.mutation.UserID(); ok {
  240. _spec.SetField(payrecharge.FieldUserID, field.TypeString, value)
  241. }
  242. if value, ok := pru.mutation.Number(); ok {
  243. _spec.SetField(payrecharge.FieldNumber, field.TypeFloat32, value)
  244. }
  245. if value, ok := pru.mutation.AddedNumber(); ok {
  246. _spec.AddField(payrecharge.FieldNumber, field.TypeFloat32, value)
  247. }
  248. if value, ok := pru.mutation.Status(); ok {
  249. _spec.SetField(payrecharge.FieldStatus, field.TypeInt, value)
  250. }
  251. if value, ok := pru.mutation.AddedStatus(); ok {
  252. _spec.AddField(payrecharge.FieldStatus, field.TypeInt, value)
  253. }
  254. if pru.mutation.StatusCleared() {
  255. _spec.ClearField(payrecharge.FieldStatus, field.TypeInt)
  256. }
  257. if value, ok := pru.mutation.Money(); ok {
  258. _spec.SetField(payrecharge.FieldMoney, field.TypeFloat32, value)
  259. }
  260. if value, ok := pru.mutation.AddedMoney(); ok {
  261. _spec.AddField(payrecharge.FieldMoney, field.TypeFloat32, value)
  262. }
  263. if pru.mutation.MoneyCleared() {
  264. _spec.ClearField(payrecharge.FieldMoney, field.TypeFloat32)
  265. }
  266. if value, ok := pru.mutation.OutTradeNo(); ok {
  267. _spec.SetField(payrecharge.FieldOutTradeNo, field.TypeString, value)
  268. }
  269. if pru.mutation.OutTradeNoCleared() {
  270. _spec.ClearField(payrecharge.FieldOutTradeNo, field.TypeString)
  271. }
  272. if value, ok := pru.mutation.OrganizationID(); ok {
  273. _spec.SetField(payrecharge.FieldOrganizationID, field.TypeUint64, value)
  274. }
  275. if value, ok := pru.mutation.AddedOrganizationID(); ok {
  276. _spec.AddField(payrecharge.FieldOrganizationID, field.TypeUint64, value)
  277. }
  278. if n, err = sqlgraph.UpdateNodes(ctx, pru.driver, _spec); err != nil {
  279. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  280. err = &NotFoundError{payrecharge.Label}
  281. } else if sqlgraph.IsConstraintError(err) {
  282. err = &ConstraintError{msg: err.Error(), wrap: err}
  283. }
  284. return 0, err
  285. }
  286. pru.mutation.done = true
  287. return n, nil
  288. }
  289. // PayRechargeUpdateOne is the builder for updating a single PayRecharge entity.
  290. type PayRechargeUpdateOne struct {
  291. config
  292. fields []string
  293. hooks []Hook
  294. mutation *PayRechargeMutation
  295. }
  296. // SetUpdatedAt sets the "updated_at" field.
  297. func (pruo *PayRechargeUpdateOne) SetUpdatedAt(t time.Time) *PayRechargeUpdateOne {
  298. pruo.mutation.SetUpdatedAt(t)
  299. return pruo
  300. }
  301. // SetDeletedAt sets the "deleted_at" field.
  302. func (pruo *PayRechargeUpdateOne) SetDeletedAt(t time.Time) *PayRechargeUpdateOne {
  303. pruo.mutation.SetDeletedAt(t)
  304. return pruo
  305. }
  306. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  307. func (pruo *PayRechargeUpdateOne) SetNillableDeletedAt(t *time.Time) *PayRechargeUpdateOne {
  308. if t != nil {
  309. pruo.SetDeletedAt(*t)
  310. }
  311. return pruo
  312. }
  313. // ClearDeletedAt clears the value of the "deleted_at" field.
  314. func (pruo *PayRechargeUpdateOne) ClearDeletedAt() *PayRechargeUpdateOne {
  315. pruo.mutation.ClearDeletedAt()
  316. return pruo
  317. }
  318. // SetUserID sets the "user_id" field.
  319. func (pruo *PayRechargeUpdateOne) SetUserID(s string) *PayRechargeUpdateOne {
  320. pruo.mutation.SetUserID(s)
  321. return pruo
  322. }
  323. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  324. func (pruo *PayRechargeUpdateOne) SetNillableUserID(s *string) *PayRechargeUpdateOne {
  325. if s != nil {
  326. pruo.SetUserID(*s)
  327. }
  328. return pruo
  329. }
  330. // SetNumber sets the "number" field.
  331. func (pruo *PayRechargeUpdateOne) SetNumber(f float32) *PayRechargeUpdateOne {
  332. pruo.mutation.ResetNumber()
  333. pruo.mutation.SetNumber(f)
  334. return pruo
  335. }
  336. // SetNillableNumber sets the "number" field if the given value is not nil.
  337. func (pruo *PayRechargeUpdateOne) SetNillableNumber(f *float32) *PayRechargeUpdateOne {
  338. if f != nil {
  339. pruo.SetNumber(*f)
  340. }
  341. return pruo
  342. }
  343. // AddNumber adds f to the "number" field.
  344. func (pruo *PayRechargeUpdateOne) AddNumber(f float32) *PayRechargeUpdateOne {
  345. pruo.mutation.AddNumber(f)
  346. return pruo
  347. }
  348. // SetStatus sets the "status" field.
  349. func (pruo *PayRechargeUpdateOne) SetStatus(i int) *PayRechargeUpdateOne {
  350. pruo.mutation.ResetStatus()
  351. pruo.mutation.SetStatus(i)
  352. return pruo
  353. }
  354. // SetNillableStatus sets the "status" field if the given value is not nil.
  355. func (pruo *PayRechargeUpdateOne) SetNillableStatus(i *int) *PayRechargeUpdateOne {
  356. if i != nil {
  357. pruo.SetStatus(*i)
  358. }
  359. return pruo
  360. }
  361. // AddStatus adds i to the "status" field.
  362. func (pruo *PayRechargeUpdateOne) AddStatus(i int) *PayRechargeUpdateOne {
  363. pruo.mutation.AddStatus(i)
  364. return pruo
  365. }
  366. // ClearStatus clears the value of the "status" field.
  367. func (pruo *PayRechargeUpdateOne) ClearStatus() *PayRechargeUpdateOne {
  368. pruo.mutation.ClearStatus()
  369. return pruo
  370. }
  371. // SetMoney sets the "money" field.
  372. func (pruo *PayRechargeUpdateOne) SetMoney(f float32) *PayRechargeUpdateOne {
  373. pruo.mutation.ResetMoney()
  374. pruo.mutation.SetMoney(f)
  375. return pruo
  376. }
  377. // SetNillableMoney sets the "money" field if the given value is not nil.
  378. func (pruo *PayRechargeUpdateOne) SetNillableMoney(f *float32) *PayRechargeUpdateOne {
  379. if f != nil {
  380. pruo.SetMoney(*f)
  381. }
  382. return pruo
  383. }
  384. // AddMoney adds f to the "money" field.
  385. func (pruo *PayRechargeUpdateOne) AddMoney(f float32) *PayRechargeUpdateOne {
  386. pruo.mutation.AddMoney(f)
  387. return pruo
  388. }
  389. // ClearMoney clears the value of the "money" field.
  390. func (pruo *PayRechargeUpdateOne) ClearMoney() *PayRechargeUpdateOne {
  391. pruo.mutation.ClearMoney()
  392. return pruo
  393. }
  394. // SetOutTradeNo sets the "out_trade_no" field.
  395. func (pruo *PayRechargeUpdateOne) SetOutTradeNo(s string) *PayRechargeUpdateOne {
  396. pruo.mutation.SetOutTradeNo(s)
  397. return pruo
  398. }
  399. // SetNillableOutTradeNo sets the "out_trade_no" field if the given value is not nil.
  400. func (pruo *PayRechargeUpdateOne) SetNillableOutTradeNo(s *string) *PayRechargeUpdateOne {
  401. if s != nil {
  402. pruo.SetOutTradeNo(*s)
  403. }
  404. return pruo
  405. }
  406. // ClearOutTradeNo clears the value of the "out_trade_no" field.
  407. func (pruo *PayRechargeUpdateOne) ClearOutTradeNo() *PayRechargeUpdateOne {
  408. pruo.mutation.ClearOutTradeNo()
  409. return pruo
  410. }
  411. // SetOrganizationID sets the "organization_id" field.
  412. func (pruo *PayRechargeUpdateOne) SetOrganizationID(u uint64) *PayRechargeUpdateOne {
  413. pruo.mutation.ResetOrganizationID()
  414. pruo.mutation.SetOrganizationID(u)
  415. return pruo
  416. }
  417. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  418. func (pruo *PayRechargeUpdateOne) SetNillableOrganizationID(u *uint64) *PayRechargeUpdateOne {
  419. if u != nil {
  420. pruo.SetOrganizationID(*u)
  421. }
  422. return pruo
  423. }
  424. // AddOrganizationID adds u to the "organization_id" field.
  425. func (pruo *PayRechargeUpdateOne) AddOrganizationID(u int64) *PayRechargeUpdateOne {
  426. pruo.mutation.AddOrganizationID(u)
  427. return pruo
  428. }
  429. // Mutation returns the PayRechargeMutation object of the builder.
  430. func (pruo *PayRechargeUpdateOne) Mutation() *PayRechargeMutation {
  431. return pruo.mutation
  432. }
  433. // Where appends a list predicates to the PayRechargeUpdate builder.
  434. func (pruo *PayRechargeUpdateOne) Where(ps ...predicate.PayRecharge) *PayRechargeUpdateOne {
  435. pruo.mutation.Where(ps...)
  436. return pruo
  437. }
  438. // Select allows selecting one or more fields (columns) of the returned entity.
  439. // The default is selecting all fields defined in the entity schema.
  440. func (pruo *PayRechargeUpdateOne) Select(field string, fields ...string) *PayRechargeUpdateOne {
  441. pruo.fields = append([]string{field}, fields...)
  442. return pruo
  443. }
  444. // Save executes the query and returns the updated PayRecharge entity.
  445. func (pruo *PayRechargeUpdateOne) Save(ctx context.Context) (*PayRecharge, error) {
  446. if err := pruo.defaults(); err != nil {
  447. return nil, err
  448. }
  449. return withHooks(ctx, pruo.sqlSave, pruo.mutation, pruo.hooks)
  450. }
  451. // SaveX is like Save, but panics if an error occurs.
  452. func (pruo *PayRechargeUpdateOne) SaveX(ctx context.Context) *PayRecharge {
  453. node, err := pruo.Save(ctx)
  454. if err != nil {
  455. panic(err)
  456. }
  457. return node
  458. }
  459. // Exec executes the query on the entity.
  460. func (pruo *PayRechargeUpdateOne) Exec(ctx context.Context) error {
  461. _, err := pruo.Save(ctx)
  462. return err
  463. }
  464. // ExecX is like Exec, but panics if an error occurs.
  465. func (pruo *PayRechargeUpdateOne) ExecX(ctx context.Context) {
  466. if err := pruo.Exec(ctx); err != nil {
  467. panic(err)
  468. }
  469. }
  470. // defaults sets the default values of the builder before save.
  471. func (pruo *PayRechargeUpdateOne) defaults() error {
  472. if _, ok := pruo.mutation.UpdatedAt(); !ok {
  473. if payrecharge.UpdateDefaultUpdatedAt == nil {
  474. return fmt.Errorf("ent: uninitialized payrecharge.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  475. }
  476. v := payrecharge.UpdateDefaultUpdatedAt()
  477. pruo.mutation.SetUpdatedAt(v)
  478. }
  479. return nil
  480. }
  481. // check runs all checks and user-defined validators on the builder.
  482. func (pruo *PayRechargeUpdateOne) check() error {
  483. if v, ok := pruo.mutation.UserID(); ok {
  484. if err := payrecharge.UserIDValidator(v); err != nil {
  485. return &ValidationError{Name: "user_id", err: fmt.Errorf(`ent: validator failed for field "PayRecharge.user_id": %w`, err)}
  486. }
  487. }
  488. if v, ok := pruo.mutation.Status(); ok {
  489. if err := payrecharge.StatusValidator(v); err != nil {
  490. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "PayRecharge.status": %w`, err)}
  491. }
  492. }
  493. if v, ok := pruo.mutation.OrganizationID(); ok {
  494. if err := payrecharge.OrganizationIDValidator(v); err != nil {
  495. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "PayRecharge.organization_id": %w`, err)}
  496. }
  497. }
  498. return nil
  499. }
  500. func (pruo *PayRechargeUpdateOne) sqlSave(ctx context.Context) (_node *PayRecharge, err error) {
  501. if err := pruo.check(); err != nil {
  502. return _node, err
  503. }
  504. _spec := sqlgraph.NewUpdateSpec(payrecharge.Table, payrecharge.Columns, sqlgraph.NewFieldSpec(payrecharge.FieldID, field.TypeUint64))
  505. id, ok := pruo.mutation.ID()
  506. if !ok {
  507. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PayRecharge.id" for update`)}
  508. }
  509. _spec.Node.ID.Value = id
  510. if fields := pruo.fields; len(fields) > 0 {
  511. _spec.Node.Columns = make([]string, 0, len(fields))
  512. _spec.Node.Columns = append(_spec.Node.Columns, payrecharge.FieldID)
  513. for _, f := range fields {
  514. if !payrecharge.ValidColumn(f) {
  515. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  516. }
  517. if f != payrecharge.FieldID {
  518. _spec.Node.Columns = append(_spec.Node.Columns, f)
  519. }
  520. }
  521. }
  522. if ps := pruo.mutation.predicates; len(ps) > 0 {
  523. _spec.Predicate = func(selector *sql.Selector) {
  524. for i := range ps {
  525. ps[i](selector)
  526. }
  527. }
  528. }
  529. if value, ok := pruo.mutation.UpdatedAt(); ok {
  530. _spec.SetField(payrecharge.FieldUpdatedAt, field.TypeTime, value)
  531. }
  532. if value, ok := pruo.mutation.DeletedAt(); ok {
  533. _spec.SetField(payrecharge.FieldDeletedAt, field.TypeTime, value)
  534. }
  535. if pruo.mutation.DeletedAtCleared() {
  536. _spec.ClearField(payrecharge.FieldDeletedAt, field.TypeTime)
  537. }
  538. if value, ok := pruo.mutation.UserID(); ok {
  539. _spec.SetField(payrecharge.FieldUserID, field.TypeString, value)
  540. }
  541. if value, ok := pruo.mutation.Number(); ok {
  542. _spec.SetField(payrecharge.FieldNumber, field.TypeFloat32, value)
  543. }
  544. if value, ok := pruo.mutation.AddedNumber(); ok {
  545. _spec.AddField(payrecharge.FieldNumber, field.TypeFloat32, value)
  546. }
  547. if value, ok := pruo.mutation.Status(); ok {
  548. _spec.SetField(payrecharge.FieldStatus, field.TypeInt, value)
  549. }
  550. if value, ok := pruo.mutation.AddedStatus(); ok {
  551. _spec.AddField(payrecharge.FieldStatus, field.TypeInt, value)
  552. }
  553. if pruo.mutation.StatusCleared() {
  554. _spec.ClearField(payrecharge.FieldStatus, field.TypeInt)
  555. }
  556. if value, ok := pruo.mutation.Money(); ok {
  557. _spec.SetField(payrecharge.FieldMoney, field.TypeFloat32, value)
  558. }
  559. if value, ok := pruo.mutation.AddedMoney(); ok {
  560. _spec.AddField(payrecharge.FieldMoney, field.TypeFloat32, value)
  561. }
  562. if pruo.mutation.MoneyCleared() {
  563. _spec.ClearField(payrecharge.FieldMoney, field.TypeFloat32)
  564. }
  565. if value, ok := pruo.mutation.OutTradeNo(); ok {
  566. _spec.SetField(payrecharge.FieldOutTradeNo, field.TypeString, value)
  567. }
  568. if pruo.mutation.OutTradeNoCleared() {
  569. _spec.ClearField(payrecharge.FieldOutTradeNo, field.TypeString)
  570. }
  571. if value, ok := pruo.mutation.OrganizationID(); ok {
  572. _spec.SetField(payrecharge.FieldOrganizationID, field.TypeUint64, value)
  573. }
  574. if value, ok := pruo.mutation.AddedOrganizationID(); ok {
  575. _spec.AddField(payrecharge.FieldOrganizationID, field.TypeUint64, value)
  576. }
  577. _node = &PayRecharge{config: pruo.config}
  578. _spec.Assign = _node.assignValues
  579. _spec.ScanValues = _node.scanValues
  580. if err = sqlgraph.UpdateNode(ctx, pruo.driver, _spec); err != nil {
  581. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  582. err = &NotFoundError{payrecharge.Label}
  583. } else if sqlgraph.IsConstraintError(err) {
  584. err = &ConstraintError{msg: err.Error(), wrap: err}
  585. }
  586. return nil, err
  587. }
  588. pruo.mutation.done = true
  589. return _node, nil
  590. }