gas_cylinder_allot.go 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175
  1. package service
  2. import (
  3. "errors"
  4. "fmt"
  5. "gas-cylinder-api/app/admin/model"
  6. "gas-cylinder-api/app/admin/service/dto"
  7. "gas-cylinder-api/common/actions"
  8. cDto "gas-cylinder-api/common/dto"
  9. "gas-cylinder-api/common/global"
  10. cModel "gas-cylinder-api/common/model"
  11. "gogs.baozhida.cn/zoie/OAuth-core/service"
  12. "gorm.io/gorm"
  13. "gorm.io/gorm/utils"
  14. "strings"
  15. "time"
  16. )
  17. type GasCylinderAllot struct {
  18. service.Service
  19. }
  20. // GetPage 获取GasCylinderAllot列表
  21. func (e *GasCylinderAllot) GetPage(c *dto.GasCylinderAllotGetPageReq, list *[]model.GasCylinderAllot, count *int64, p *actions.DataPermission) error {
  22. var err error
  23. var data model.GasCylinderAllot
  24. if c.My == "allot" {
  25. err = e.Orm.Model(&data).
  26. Scopes(
  27. cDto.MakeCondition(c.GetNeedSearch()),
  28. cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
  29. actions.Permission(data.TableName(), p),
  30. ).
  31. Where("allot_user_id = ? ", p.UserId).
  32. Preload("AllotUser").
  33. Preload("AcceptUser").
  34. Preload("AllotCompany").
  35. Preload("AcceptCompany").
  36. Find(list).Limit(-1).Offset(-1).
  37. Count(count).Error
  38. }
  39. if c.My == "accept" {
  40. err = e.Orm.Model(&data).
  41. Scopes(
  42. cDto.MakeCondition(c.GetNeedSearch()),
  43. cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
  44. actions.Permission(data.TableName(), p),
  45. ).
  46. Where("accept_user_id = ?", p.UserId).
  47. Preload("AllotUser").
  48. Preload("AcceptUser").
  49. Preload("AllotCompany").
  50. Preload("AcceptCompany").
  51. Find(list).Limit(-1).Offset(-1).
  52. Count(count).Error
  53. }
  54. if err != nil {
  55. e.Log.Errorf("db error: %s", err)
  56. return global.GetFailedErr
  57. }
  58. return nil
  59. }
  60. // Get 获取GasCylinderAllot对象
  61. func (e *GasCylinderAllot) Get(d *dto.GasCylinderAllotGetReq, gasCylinderAllotModel *model.GasCylinderAllot, p *actions.DataPermission) error {
  62. err := e.Orm.
  63. Scopes(actions.Permission(gasCylinderAllotModel.TableName(), p)).
  64. Preload("AllotUser").
  65. Preload("AcceptUser").
  66. Preload("AllotCompany").
  67. Preload("AcceptCompany").
  68. First(gasCylinderAllotModel, d.GetId()).Error
  69. if err != nil {
  70. e.Log.Errorf("db error: %s", err)
  71. if errors.Is(err, gorm.ErrRecordNotFound) {
  72. return global.GetNotFoundOrNoPermissionErr
  73. }
  74. return global.GetFailedErr
  75. }
  76. return nil
  77. }
  78. // ByOptType 获取GasCylinderAllot对象
  79. func (e *GasCylinderAllot) GetByOptType(d *dto.GasCylinderAllotGetByOptTypeReq, gasCylinderAllotModel *model.GasCylinderAllot, p *actions.DataPermission) error {
  80. err := e.Orm.
  81. Where("opt_type = ? and accept_user_id = ? and status = ? and allot_type = 1", d.OptType, p.UserId, model.GasCylinderAllotStateAllot).
  82. Preload("AllotUser").
  83. Preload("AllotCompany").
  84. First(gasCylinderAllotModel).Error
  85. if err != nil {
  86. e.Log.Errorf("db error: %s", err)
  87. if errors.Is(err, gorm.ErrRecordNotFound) {
  88. return global.GetNotFoundOrNoPermissionErr
  89. }
  90. return global.GetFailedErr
  91. }
  92. return nil
  93. }
  94. // Insert 创建GasCylinderAllot对象
  95. func (e *GasCylinderAllot) Insert(c *dto.GasCylinderAllotInsertReq) error {
  96. var err error
  97. var data model.GasCylinderAllot
  98. if err = e.Check(c); err != nil {
  99. return err
  100. }
  101. tx := e.Orm.Begin()
  102. defer func() {
  103. if err != nil {
  104. tx.Rollback()
  105. } else {
  106. tx.Commit()
  107. }
  108. }()
  109. err = e.Orm.
  110. Where("opt_type = ? and accept_user_id = ? and status = ? and allot_type = 1", c.OptType, c.AcceptUserId, model.GasCylinderAllotStateAllot).
  111. First(&data).Error
  112. if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
  113. e.Log.Errorf("db error: %s", err)
  114. return global.GetFailedErr
  115. }
  116. // 扫码调拨未接收不能重复提交
  117. if data.Id > 0 {
  118. err = errors.New("调拨中,请勿重复提交!")
  119. return err
  120. }
  121. list := make([]model.GasCylinderAllot, 0)
  122. err = e.Orm.
  123. Where("allot_user_id = ? and status = ? and allot_type = 2", c.CreateBy, model.GasCylinderAllotStateAllot).
  124. Find(&list).Error
  125. // 扫码调拨未接收不能重复提交
  126. for _, status := range list {
  127. isEqual, common, _, _ := global.StringListCompare(status.InnerCodeList, c.InnerCodeList)
  128. if isEqual || len(common) > 0 {
  129. err = errors.New(fmt.Sprintf("钢瓶%s调拨中,请勿重复提交!", strings.Join(common, ",")))
  130. return err
  131. }
  132. }
  133. err = e.VerifyGasCylinderStatus(c.OptType, c.AcceptUserId, c.CreateBy, c.InnerCodeList)
  134. if err != nil {
  135. return err
  136. }
  137. // 添加调拨信息
  138. data.Id = 0
  139. c.Generate(&data)
  140. // 修改钢瓶状态为调拨中
  141. var InnerCodeList []string
  142. for _, v := range c.InnerCodeList {
  143. InnerCodeList = append(InnerCodeList, v)
  144. }
  145. err = e.Orm.Model(&model.GasCylinderStatus{}).
  146. Where("company_id = ? and inner_code in (?)", data.AllotCompanyId, InnerCodeList).
  147. Update("is_allot", true).Error
  148. if err != nil {
  149. e.Log.Errorf("db error: %s", err)
  150. return global.CreateFailedErr
  151. }
  152. err = tx.Create(&data).Error
  153. if err != nil {
  154. e.Log.Errorf("db error: %s", err)
  155. return global.CreateFailedErr
  156. }
  157. c.Id = data.Id
  158. return nil
  159. }
  160. func (e *GasCylinderAllot) Check(c *dto.GasCylinderAllotInsertReq) error {
  161. if global.CheckElementExists(c.OptType, []string{"016", "17", "033", "31", "35", "25"}) {
  162. if c.GasCylinderStatus != model.GasCylinderStatusWeighty {
  163. return errors.New("该流转步骤仅能接收重瓶!")
  164. }
  165. }
  166. if global.CheckElementExists(c.OptType, []string{"11", "13", "21"}) {
  167. if c.GasCylinderStatus != model.GasCylinderStatusEmpty {
  168. return errors.New("该流转步骤仅能接收空瓶!")
  169. }
  170. }
  171. if global.CheckElementExists(c.OptType, []string{"Unqualified"}) {
  172. if c.GasCylinderStatus != model.GasCylinderStatusUnqualified {
  173. return errors.New("该流转步骤仅能接收不合格瓶!")
  174. }
  175. }
  176. return nil
  177. }
  178. // Update 修改GasCylinderAllot对象
  179. func (e *GasCylinderAllot) Update(c *dto.GasCylinderAllotUpdateReq, p *actions.DataPermission) error {
  180. var err error
  181. tx := e.Orm.Begin()
  182. defer func() {
  183. if err != nil {
  184. tx.Rollback()
  185. } else {
  186. tx.Commit()
  187. }
  188. }()
  189. var gasCylinderAllotModel = model.GasCylinderAllot{}
  190. // 查询调拨信息是否存在
  191. err = e.Orm.Scopes(actions.Permission(gasCylinderAllotModel.TableName(), p)).
  192. First(&gasCylinderAllotModel, c.GetId()).Error
  193. if err != nil {
  194. e.Log.Errorf("db error: %s", err)
  195. if errors.Is(err, gorm.ErrRecordNotFound) {
  196. return global.UpdateNotFoundOrNoPermissionErr
  197. }
  198. return global.UpdateFailedErr
  199. }
  200. c.Generate(&gasCylinderAllotModel)
  201. err = tx.Save(&gasCylinderAllotModel).Error
  202. if err != nil {
  203. e.Log.Errorf("db error: %s", err)
  204. return global.UpdateFailedErr
  205. }
  206. c.Id = gasCylinderAllotModel.Id
  207. return nil
  208. }
  209. // Remove 删除GasCylinderAllot
  210. func (e *GasCylinderAllot) Remove(c *dto.GasCylinderAllotDeleteReq, p *actions.DataPermission) error {
  211. var err error
  212. tx := e.Orm.Begin()
  213. defer func() {
  214. if err != nil {
  215. tx.Rollback()
  216. } else {
  217. tx.Commit()
  218. }
  219. }()
  220. var gasCylinderAllotModel model.GasCylinderAllot
  221. // 查询调拨信息是否存在
  222. err = e.Orm.Scopes(actions.Permission(gasCylinderAllotModel.TableName(), p)).
  223. First(&gasCylinderAllotModel, c.GetId()).Error
  224. if err != nil {
  225. e.Log.Errorf("db error: %s", err)
  226. if errors.Is(err, gorm.ErrRecordNotFound) {
  227. return global.DeleteNotFoundOrNoPermissionErr
  228. }
  229. return global.DeleteFailedErr
  230. }
  231. if gasCylinderAllotModel.Status != model.GasCylinderAllotStateCancel {
  232. err = errors.New(fmt.Sprintf("状态为%s,无法删除", model.GasCylinderAllotStateMap[gasCylinderAllotModel.Status]))
  233. return err
  234. }
  235. db := tx.Delete(&gasCylinderAllotModel)
  236. if err = db.Error; err != nil {
  237. e.Log.Errorf("db error: %s", err)
  238. return global.DeleteFailedErr
  239. }
  240. if db.RowsAffected == 0 {
  241. return global.DeleteNotFoundOrNoPermissionErr
  242. }
  243. return nil
  244. }
  245. // Cancel 取消GasCylinderAllot
  246. func (e *GasCylinderAllot) Cancel(c *dto.GasCylinderAllotCancelReq, p *actions.DataPermission) error {
  247. var err error
  248. tx := e.Orm.Begin()
  249. defer func() {
  250. if err != nil {
  251. tx.Rollback()
  252. } else {
  253. tx.Commit()
  254. }
  255. }()
  256. var gasCylinderAllotModel = model.GasCylinderAllot{}
  257. // 查询调拨信息是否存在
  258. err = e.Orm.Scopes(actions.Permission(gasCylinderAllotModel.TableName(), p)).
  259. First(&gasCylinderAllotModel, c.GetId()).Error
  260. if err != nil {
  261. e.Log.Errorf("db error: %s", err)
  262. if errors.Is(err, gorm.ErrRecordNotFound) {
  263. return global.UpdateNotFoundOrNoPermissionErr
  264. }
  265. return global.UpdateFailedErr
  266. }
  267. if gasCylinderAllotModel.Status != model.GasCylinderAllotStateAllot {
  268. err = errors.New(fmt.Sprintf("状态为%s,无法取消", model.GasCylinderAllotStateMap[gasCylinderAllotModel.Status]))
  269. return err
  270. }
  271. gasCylinderAllotModel.Status = model.GasCylinderAllotStateCancel
  272. err = tx.Save(&gasCylinderAllotModel).Error
  273. if err != nil {
  274. e.Log.Errorf("db error: %s", err)
  275. return global.UpdateFailedErr
  276. }
  277. var InnerCodeList []string
  278. for _, v := range gasCylinderAllotModel.InnerCodeList {
  279. InnerCodeList = append(InnerCodeList, v)
  280. }
  281. err = e.Orm.Model(&model.GasCylinderStatus{}).
  282. Where("company_id = ? and inner_code in (?)", gasCylinderAllotModel.AllotCompanyId, InnerCodeList).
  283. Update("is_allot", false).Error
  284. if err != nil {
  285. e.Log.Errorf("db error: %s", err)
  286. return global.CreateFailedErr
  287. }
  288. c.Id = gasCylinderAllotModel.Id
  289. return nil
  290. }
  291. // Submit 提交GasCylinderAllot
  292. func (e *GasCylinderAllot) Submit(c *dto.GasCylinderAllotSubmitReq, p *actions.DataPermission) error {
  293. var err error
  294. tx := e.Orm.Begin()
  295. defer func() {
  296. if err != nil {
  297. tx.Rollback()
  298. } else {
  299. tx.Commit()
  300. }
  301. }()
  302. // 调拨状态更新为 已完成
  303. // 调拨者气瓶状态更新
  304. // 接收更新气瓶状态 上报气瓶流转信息
  305. // 调拨更新气瓶状态 上报气瓶流转信息
  306. var gasCylinderAllotModel = model.GasCylinderAllot{}
  307. // 查询调拨信息是否存在
  308. err = e.Orm.First(&gasCylinderAllotModel, c.GetId()).Error
  309. if err != nil {
  310. e.Log.Errorf("db error: %s", err)
  311. if errors.Is(err, gorm.ErrRecordNotFound) {
  312. return errors.New("调拨信息不存在!")
  313. }
  314. return errors.New("查询调拨信息失败!")
  315. }
  316. if gasCylinderAllotModel.Status != model.GasCylinderAllotStateAllot {
  317. err = errors.New(fmt.Sprintf("状态为%s,无法提交", model.GasCylinderAllotStateMap[gasCylinderAllotModel.Status]))
  318. return err
  319. }
  320. if !global.ContainsAllOptimized(gasCylinderAllotModel.InnerCodeList, c.InnerCodeList) {
  321. err = errors.New("请提交正确的单位内编码!")
  322. return err
  323. }
  324. err = e.VerifyGasCylinderStatus(gasCylinderAllotModel.OptType, gasCylinderAllotModel.AcceptUserId, gasCylinderAllotModel.AllotUserId, c.InnerCodeList)
  325. if err != nil {
  326. return err
  327. }
  328. gasCylinderAllotModel.AcceptInnerCodeList = c.InnerCodeList
  329. gasCylinderAllotModel.Status = model.GasCylinderAllotStateFinish
  330. err = tx.Save(&gasCylinderAllotModel).Error
  331. if err != nil {
  332. e.Log.Errorf("db error: %s", err)
  333. return global.UpdateFailedErr
  334. }
  335. // 修改钢瓶状态为未调拨
  336. // 修改钢瓶状态为调拨中
  337. var InnerCodeList []string
  338. for _, v := range gasCylinderAllotModel.InnerCodeList {
  339. InnerCodeList = append(InnerCodeList, v)
  340. }
  341. err = e.Orm.Model(&model.GasCylinderStatus{}).
  342. Where("company_id = ? and inner_code in (?)", gasCylinderAllotModel.AllotCompanyId, InnerCodeList).
  343. Update("is_allot", false).Error
  344. if err != nil {
  345. e.Log.Errorf("db error: %s", err)
  346. return global.CreateFailedErr
  347. }
  348. c.Id = gasCylinderAllotModel.Id
  349. acceptUser, err := model.GetUserCode(c.AcceptUserId)
  350. if err != nil {
  351. e.Log.Errorf("db error: %s", err)
  352. return global.CreateFailedErr
  353. }
  354. allotUser, err := model.GetUserCode(c.AllotUserId)
  355. if err != nil {
  356. e.Log.Errorf("db error: %s", err)
  357. return global.CreateFailedErr
  358. }
  359. data := make([]model.OperationLog, 0)
  360. batchNumber := fmt.Sprintf("%03d%s", p.DeptId, time.Now().Format("20060102150405"))
  361. optTime := time.Now().Format("2006-01-02 15:04:05")
  362. switch c.OptType {
  363. case "25":
  364. // 25送气员领重瓶 37 门店重瓶出库
  365. for _, innerCode := range c.InnerCodeList {
  366. // 25送气员领重瓶
  367. operationLog25 := model.OperationLog{
  368. BatchNumber: batchNumber,
  369. ProvOperationLog: model.ProvOperationLog{
  370. InnerCode: innerCode,
  371. OptType: c.OptType,
  372. OptUser: acceptUser.ProvUserId,
  373. ObjectUser: acceptUser.ProvUserId,
  374. CompanyId: acceptUser.ProvUser.CmpCode,
  375. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  376. CurrentStore: acceptUser.Dept.CmpCode,
  377. Lng: utils.ToString(acceptUser.Dept.ProvStore.Lng),
  378. Lat: utils.ToString(acceptUser.Dept.ProvStore.Lat),
  379. OptTime: optTime,
  380. },
  381. ControlBy: cModel.ControlBy{
  382. CreateBy: p.UserId,
  383. },
  384. DeptBy: cModel.DeptBy{
  385. DeptId: acceptUser.DeptId,
  386. },
  387. }
  388. data = append(data, operationLog25)
  389. // 37 门店重瓶出库
  390. operationLog37 := model.OperationLog{
  391. BatchNumber: batchNumber,
  392. ProvOperationLog: model.ProvOperationLog{
  393. InnerCode: innerCode,
  394. OptType: "37",
  395. OptUser: allotUser.ProvUserId,
  396. ObjectUser: allotUser.ProvUserId,
  397. CompanyId: allotUser.ProvUser.CmpCode,
  398. CurrentEnterprise: allotUser.ProvUser.CmpCode,
  399. CurrentStore: allotUser.ProvUser.CmpCode,
  400. Lng: utils.ToString(allotUser.Dept.ProvStore.Lng),
  401. Lat: utils.ToString(allotUser.Dept.ProvStore.Lat),
  402. OptTime: optTime,
  403. },
  404. ControlBy: cModel.ControlBy{
  405. CreateBy: p.UserId,
  406. },
  407. DeptBy: cModel.DeptBy{
  408. DeptId: allotUser.DeptId,
  409. },
  410. }
  411. data = append(data, operationLog37)
  412. gasCylinderStatus := &model.GasCylinderStatus{
  413. InnerCode: innerCode,
  414. UserId: acceptUser.Id,
  415. CompanyId: acceptUser.Dept.Id,
  416. Status: model.GasCylinderStatusWeighty,
  417. ControlBy: cModel.ControlBy{
  418. CreateBy: p.UserId,
  419. },
  420. DeptBy: cModel.DeptBy{
  421. DeptId: acceptUser.DeptId,
  422. },
  423. }
  424. // 添加送气员重瓶
  425. err = tx.Where(model.GasCylinderStatus{InnerCode: innerCode, UserId: acceptUser.Id, CompanyId: acceptUser.Dept.Id}).
  426. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
  427. if err != nil {
  428. e.Log.Errorf("db error: %s", err)
  429. return global.CreateFailedErr
  430. }
  431. }
  432. // 删除门店重瓶
  433. err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?", c.InnerCodeList, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
  434. Delete(&model.GasCylinderStatus{}).Error
  435. if err != nil {
  436. e.Log.Errorf("db error: %s", err)
  437. return global.CreateFailedErr
  438. }
  439. case "21":
  440. // 21门店回收空瓶 27送气员回收空瓶
  441. for _, innerCode := range c.InnerCodeList {
  442. // 21门店回收空瓶
  443. operationLog21 := model.OperationLog{
  444. BatchNumber: batchNumber,
  445. ProvOperationLog: model.ProvOperationLog{
  446. InnerCode: innerCode,
  447. OptType: c.OptType,
  448. ObjectUser: acceptUser.ProvUserId,
  449. OptUser: acceptUser.ProvUserId,
  450. CompanyId: acceptUser.ProvUser.CmpCode,
  451. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  452. CurrentStore: acceptUser.ProvUser.CmpCode,
  453. Lng: utils.ToString(acceptUser.Dept.ProvStore.Lng),
  454. Lat: utils.ToString(acceptUser.Dept.ProvStore.Lat),
  455. OptTime: optTime,
  456. },
  457. ControlBy: cModel.ControlBy{
  458. CreateBy: p.UserId,
  459. },
  460. DeptBy: cModel.DeptBy{
  461. DeptId: p.DeptId,
  462. },
  463. }
  464. data = append(data, operationLog21)
  465. // 添加门店空瓶
  466. gasCylinderStatus := &model.GasCylinderStatus{
  467. InnerCode: innerCode,
  468. UserId: 0,
  469. CompanyId: acceptUser.Dept.Id,
  470. Status: model.GasCylinderStatusWeighty,
  471. ControlBy: cModel.ControlBy{
  472. CreateBy: p.UserId,
  473. },
  474. DeptBy: cModel.DeptBy{
  475. DeptId: acceptUser.DeptId,
  476. },
  477. }
  478. err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", innerCode, acceptUser.Dept.Id).
  479. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusEmpty}).FirstOrCreate(&gasCylinderStatus).Error
  480. if err != nil {
  481. e.Log.Errorf("db error: %s", err)
  482. return global.CreateFailedErr
  483. }
  484. }
  485. // 删除送气员空瓶
  486. err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?", c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusEmpty).
  487. Delete(&model.GasCylinderStatus{}).Error
  488. if err != nil {
  489. e.Log.Errorf("db error: %s", err)
  490. return global.CreateFailedErr
  491. }
  492. case "11":
  493. // 10 门店空瓶出库 11 司机确认空瓶装车
  494. var truckUserCarInfo model.TruckUserCarInfo
  495. err = tx.Where("prov_user_id = ?", acceptUser.ProvUserId).First(&truckUserCarInfo).Error
  496. if err != nil {
  497. tx.Rollback()
  498. e.Log.Errorf("获取车辆信息失败: %s", err)
  499. if err == gorm.ErrRecordNotFound {
  500. return errors.New("该司机未绑定车辆,请先绑定车辆!")
  501. }
  502. return errors.New("获取车辆信息失败")
  503. }
  504. for _, innerCode := range c.InnerCodeList {
  505. // 10 门店空瓶出库
  506. operationLog10 := model.OperationLog{
  507. BatchNumber: batchNumber,
  508. ProvOperationLog: model.ProvOperationLog{
  509. InnerCode: innerCode,
  510. OptType: "10",
  511. ObjectUser: acceptUser.ProvUserId,
  512. OptUser: allotUser.ProvUserId,
  513. CompanyId: allotUser.ProvUser.CmpCode,
  514. CurrentEnterprise: allotUser.ProvUser.CmpCode,
  515. CurrentStore: allotUser.ProvUser.CmpCode,
  516. Lng: utils.ToString(allotUser.Dept.ProvStore.Lng),
  517. Lat: utils.ToString(allotUser.Dept.ProvStore.Lat),
  518. OptTime: optTime,
  519. },
  520. ControlBy: cModel.ControlBy{
  521. CreateBy: p.UserId,
  522. },
  523. DeptBy: cModel.DeptBy{
  524. DeptId: allotUser.DeptId,
  525. },
  526. }
  527. data = append(data, operationLog10)
  528. // 11 司机确认空瓶装车
  529. operationLog11 := model.OperationLog{
  530. BatchNumber: batchNumber,
  531. ProvOperationLog: model.ProvOperationLog{
  532. InnerCode: innerCode,
  533. OptType: c.OptType,
  534. ObjectUser: acceptUser.ProvUserId,
  535. OptUser: acceptUser.ProvUserId,
  536. CompanyId: acceptUser.ProvUser.CmpCode,
  537. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  538. CurrentStore: allotUser.ProvUser.CmpCode,
  539. CurrentTruck: acceptUser.ProvUserId,
  540. CurrentMotor: truckUserCarInfo.CarNo,
  541. OptTime: optTime,
  542. },
  543. ControlBy: cModel.ControlBy{
  544. CreateBy: p.UserId,
  545. },
  546. DeptBy: cModel.DeptBy{
  547. DeptId: acceptUser.DeptId,
  548. },
  549. }
  550. data = append(data, operationLog11)
  551. gasCylinderStatus := &model.GasCylinderStatus{
  552. InnerCode: innerCode,
  553. UserId: acceptUser.Id,
  554. CompanyId: acceptUser.Dept.Id,
  555. Status: model.GasCylinderStatusWeighty,
  556. ControlBy: cModel.ControlBy{
  557. CreateBy: p.UserId,
  558. },
  559. DeptBy: cModel.DeptBy{
  560. DeptId: acceptUser.DeptId,
  561. },
  562. }
  563. // 添加司机空瓶
  564. err = tx.Where(model.GasCylinderStatus{InnerCode: innerCode, UserId: acceptUser.Id, CompanyId: acceptUser.Dept.Id}).
  565. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusEmpty}).FirstOrCreate(&gasCylinderStatus).Error
  566. if err != nil {
  567. e.Log.Errorf("db error: %s", err)
  568. return global.CreateFailedErr
  569. }
  570. }
  571. // 删除门店空瓶
  572. err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?", c.InnerCodeList, allotUser.Dept.Id, model.GasCylinderStatusEmpty).
  573. Delete(&model.GasCylinderStatus{}).Error
  574. if err != nil {
  575. e.Log.Errorf("db error: %s", err)
  576. return global.CreateFailedErr
  577. }
  578. case "13":
  579. // 12 司机运输空瓶到达气站 13 气站确认空瓶到达气站
  580. var truckUserCarInfo model.TruckUserCarInfo
  581. err = tx.Where("prov_user_id = ?", allotUser.ProvUserId).First(&truckUserCarInfo).Error
  582. if err != nil {
  583. tx.Rollback()
  584. e.Log.Errorf("获取车辆信息失败: %s", err)
  585. if err == gorm.ErrRecordNotFound {
  586. return errors.New("该司机未绑定车辆,请先绑定车辆!")
  587. }
  588. return errors.New("获取车辆信息失败")
  589. }
  590. for _, innerCode := range c.InnerCodeList {
  591. // 12 司机运输空瓶到达气站
  592. operationLog12 := model.OperationLog{
  593. BatchNumber: batchNumber,
  594. ProvOperationLog: model.ProvOperationLog{
  595. InnerCode: innerCode,
  596. OptType: "12",
  597. ObjectUser: allotUser.ProvUserId,
  598. OptUser: allotUser.ProvUserId,
  599. CompanyId: allotUser.ProvUser.CmpCode,
  600. CurrentEnterprise: allotUser.ProvUser.CmpCode,
  601. CurrentStation: acceptUser.ProvUser.CmpCode,
  602. CurrentTruck: allotUser.ProvUserId,
  603. CurrentMotor: truckUserCarInfo.CarNo,
  604. OptTime: optTime,
  605. },
  606. ControlBy: cModel.ControlBy{
  607. CreateBy: p.UserId,
  608. },
  609. DeptBy: cModel.DeptBy{
  610. DeptId: p.DeptId,
  611. },
  612. }
  613. data = append(data, operationLog12)
  614. // 13 气站确认空瓶到达气站
  615. operationLog13 := model.OperationLog{
  616. BatchNumber: batchNumber,
  617. ProvOperationLog: model.ProvOperationLog{
  618. InnerCode: innerCode,
  619. OptType: c.OptType,
  620. ObjectUser: acceptUser.ProvUserId,
  621. OptUser: acceptUser.ProvUserId,
  622. CompanyId: acceptUser.ProvUser.CmpCode,
  623. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  624. CurrentStation: acceptUser.ProvUser.CmpCode,
  625. Lng: utils.ToString(acceptUser.Dept.ProvStore.Lng),
  626. Lat: utils.ToString(acceptUser.Dept.ProvStore.Lat),
  627. OptTime: optTime,
  628. },
  629. ControlBy: cModel.ControlBy{
  630. CreateBy: p.UserId,
  631. },
  632. DeptBy: cModel.DeptBy{
  633. DeptId: p.DeptId,
  634. },
  635. }
  636. data = append(data, operationLog13)
  637. gasCylinderStatus := &model.GasCylinderStatus{
  638. InnerCode: innerCode,
  639. UserId: 0,
  640. CompanyId: acceptUser.Dept.Id,
  641. Status: model.GasCylinderStatusEmpty,
  642. ControlBy: cModel.ControlBy{
  643. CreateBy: p.UserId,
  644. },
  645. DeptBy: cModel.DeptBy{
  646. DeptId: acceptUser.DeptId,
  647. },
  648. }
  649. // 添加气站空瓶
  650. err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", innerCode, acceptUser.Dept.Id).
  651. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusEmpty}).FirstOrCreate(&gasCylinderStatus).Error
  652. if err != nil {
  653. e.Log.Errorf("db error: %s", err)
  654. return global.CreateFailedErr
  655. }
  656. }
  657. // 删除司机空瓶
  658. err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?", c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusEmpty).
  659. Delete(&model.GasCylinderStatus{}).Error
  660. if err != nil {
  661. e.Log.Errorf("db error: %s", err)
  662. return global.CreateFailedErr
  663. }
  664. case "17":
  665. // 15 气站重瓶出库 17 司机确认重瓶从气站出库
  666. var truckUserCarInfo model.TruckUserCarInfo
  667. err = tx.Where("prov_user_id = ?", acceptUser.ProvUserId).First(&truckUserCarInfo).Error
  668. if err != nil {
  669. tx.Rollback()
  670. e.Log.Errorf("获取车辆信息失败: %s", err)
  671. if err == gorm.ErrRecordNotFound {
  672. return errors.New("该司机未绑定车辆,请先绑定车辆!")
  673. }
  674. return errors.New("获取车辆信息失败")
  675. }
  676. for _, innerCode := range c.InnerCodeList {
  677. // 15 气站重瓶出库
  678. operationLog15 := model.OperationLog{
  679. BatchNumber: batchNumber,
  680. ProvOperationLog: model.ProvOperationLog{
  681. InnerCode: innerCode,
  682. OptType: "15",
  683. OptUser: allotUser.ProvUserId,
  684. ObjectUser: allotUser.ProvUserId,
  685. CompanyId: allotUser.ProvUser.CmpCode,
  686. CurrentEnterprise: allotUser.ProvUser.CmpCode,
  687. CurrentStation: allotUser.ProvUser.CmpCode,
  688. Lng: utils.ToString(allotUser.Dept.ProvStore.Lng),
  689. Lat: utils.ToString(allotUser.Dept.ProvStore.Lat),
  690. OptTime: optTime,
  691. },
  692. ControlBy: cModel.ControlBy{
  693. CreateBy: p.UserId,
  694. },
  695. DeptBy: cModel.DeptBy{
  696. DeptId: allotUser.DeptId,
  697. },
  698. }
  699. data = append(data, operationLog15)
  700. // 17 司机确认重瓶从气站出库
  701. operationLog17 := model.OperationLog{
  702. BatchNumber: batchNumber,
  703. ProvOperationLog: model.ProvOperationLog{
  704. InnerCode: innerCode,
  705. OptType: c.OptType,
  706. OptUser: acceptUser.ProvUserId,
  707. CompanyId: acceptUser.ProvUser.CmpCode,
  708. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  709. CurrentStation: allotUser.ProvUser.CmpCode,
  710. CurrentTruck: acceptUser.ProvUserId,
  711. CurrentMotor: truckUserCarInfo.CarNo,
  712. OptTime: optTime,
  713. },
  714. ControlBy: cModel.ControlBy{
  715. CreateBy: p.UserId,
  716. },
  717. DeptBy: cModel.DeptBy{
  718. DeptId: acceptUser.DeptId,
  719. },
  720. }
  721. data = append(data, operationLog17)
  722. // 司机添加重瓶
  723. gasCylinderStatus := &model.GasCylinderStatus{
  724. InnerCode: innerCode,
  725. UserId: acceptUser.Id,
  726. CompanyId: acceptUser.Dept.Id,
  727. Status: model.GasCylinderStatusWeighty,
  728. ControlBy: cModel.ControlBy{
  729. CreateBy: p.UserId,
  730. },
  731. DeptBy: cModel.DeptBy{
  732. DeptId: acceptUser.DeptId,
  733. },
  734. }
  735. err = tx.Where(model.GasCylinderStatus{InnerCode: innerCode, UserId: acceptUser.Id, CompanyId: acceptUser.Dept.Id}).
  736. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
  737. if err != nil {
  738. e.Log.Errorf("db error: %s", err)
  739. return global.CreateFailedErr
  740. }
  741. }
  742. // 删除气站重瓶
  743. err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?", c.InnerCodeList, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
  744. Delete(&model.GasCylinderStatus{}).Error
  745. if err != nil {
  746. e.Log.Errorf("db error: %s", err)
  747. return global.CreateFailedErr
  748. }
  749. case "31":
  750. // 19 司机交付门店 31 门店确认重瓶卸货入库
  751. var truckUserCarInfo model.TruckUserCarInfo
  752. err = tx.Where("prov_user_id = ?", allotUser.ProvUserId).First(&truckUserCarInfo).Error
  753. if err != nil {
  754. tx.Rollback()
  755. e.Log.Errorf("获取车辆信息失败: %s", err)
  756. if err == gorm.ErrRecordNotFound {
  757. return errors.New("该司机未绑定车辆,请先绑定车辆!")
  758. }
  759. return errors.New("获取车辆信息失败")
  760. }
  761. for _, innerCode := range c.InnerCodeList {
  762. // 19 司机交付门店
  763. operationLog19 := model.OperationLog{
  764. BatchNumber: batchNumber,
  765. ProvOperationLog: model.ProvOperationLog{
  766. InnerCode: innerCode,
  767. OptType: "19",
  768. OptUser: allotUser.ProvUserId,
  769. ObjectUser: allotUser.ProvUserId,
  770. CompanyId: allotUser.ProvUser.CmpCode,
  771. CurrentEnterprise: allotUser.ProvUser.CmpCode,
  772. CurrentStore: acceptUser.ProvUser.CmpCode,
  773. CurrentTruck: allotUser.ProvUserId,
  774. CurrentMotor: truckUserCarInfo.CarNo,
  775. OptTime: optTime,
  776. },
  777. ControlBy: cModel.ControlBy{
  778. CreateBy: p.UserId,
  779. },
  780. DeptBy: cModel.DeptBy{
  781. DeptId: allotUser.DeptId,
  782. },
  783. }
  784. data = append(data, operationLog19)
  785. // 31 门店确认重瓶卸货入库
  786. operationLog31 := model.OperationLog{
  787. BatchNumber: batchNumber,
  788. ProvOperationLog: model.ProvOperationLog{
  789. InnerCode: innerCode,
  790. OptType: c.OptType,
  791. OptUser: acceptUser.ProvUserId,
  792. ObjectUser: acceptUser.ProvUserId,
  793. CompanyId: acceptUser.ProvUser.CmpCode,
  794. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  795. CurrentStore: acceptUser.ProvUser.CmpCode,
  796. CurrentTruck: acceptUser.ProvUserId,
  797. CurrentMotor: truckUserCarInfo.CarNo,
  798. OptTime: optTime,
  799. },
  800. ControlBy: cModel.ControlBy{
  801. CreateBy: p.UserId,
  802. },
  803. DeptBy: cModel.DeptBy{
  804. DeptId: acceptUser.DeptId,
  805. },
  806. }
  807. data = append(data, operationLog31)
  808. gasCylinderStatus := &model.GasCylinderStatus{
  809. InnerCode: innerCode,
  810. UserId: 0,
  811. CompanyId: acceptUser.Dept.Id,
  812. Status: model.GasCylinderStatusWeighty,
  813. ControlBy: cModel.ControlBy{
  814. CreateBy: p.UserId,
  815. },
  816. DeptBy: cModel.DeptBy{
  817. DeptId: acceptUser.DeptId,
  818. },
  819. }
  820. // 门店添加重瓶
  821. err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", innerCode, acceptUser.Dept.Id).
  822. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
  823. if err != nil {
  824. e.Log.Errorf("db error: %s", err)
  825. return global.CreateFailedErr
  826. }
  827. }
  828. // 删除司机重瓶
  829. err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
  830. c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
  831. Delete(&model.GasCylinderStatus{}).Error
  832. if err != nil {
  833. e.Log.Errorf("db error: %s", err)
  834. return global.CreateFailedErr
  835. }
  836. case "35":
  837. // 35 门店确认未配送重瓶返库
  838. for _, innerCode := range c.InnerCodeList {
  839. operationLog35 := model.OperationLog{
  840. BatchNumber: batchNumber,
  841. ProvOperationLog: model.ProvOperationLog{
  842. InnerCode: innerCode,
  843. OptType: c.OptType,
  844. OptUser: acceptUser.ProvUserId,
  845. CompanyId: acceptUser.ProvUser.CmpCode,
  846. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  847. CurrentStore: acceptUser.ProvUser.CmpCode,
  848. Lng: utils.ToString(acceptUser.Dept.ProvStore.Lng),
  849. Lat: utils.ToString(acceptUser.Dept.ProvStore.Lat),
  850. OptTime: optTime,
  851. },
  852. ControlBy: cModel.ControlBy{
  853. CreateBy: p.UserId,
  854. },
  855. DeptBy: cModel.DeptBy{
  856. DeptId: p.DeptId,
  857. },
  858. }
  859. data = append(data, operationLog35)
  860. gasCylinderStatus := &model.GasCylinderStatus{
  861. InnerCode: innerCode,
  862. UserId: 0,
  863. CompanyId: acceptUser.Dept.Id,
  864. Status: model.GasCylinderStatusWeighty,
  865. ControlBy: cModel.ControlBy{
  866. CreateBy: p.UserId,
  867. },
  868. DeptBy: cModel.DeptBy{
  869. DeptId: acceptUser.DeptId,
  870. },
  871. }
  872. // 门店添加重瓶
  873. err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", innerCode, acceptUser.Dept.Id).
  874. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
  875. if err != nil {
  876. e.Log.Errorf("db error: %s", err)
  877. return global.CreateFailedErr
  878. }
  879. }
  880. // 删除送气员重瓶
  881. err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
  882. c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
  883. Delete(&model.GasCylinderStatus{}).Error
  884. if err != nil {
  885. e.Log.Errorf("db error: %s", err)
  886. return global.CreateFailedErr
  887. }
  888. case "033":
  889. // 33 门店将重瓶退回司机
  890. var truckUserCarInfo model.TruckUserCarInfo
  891. // 2、上报气瓶流转信息
  892. err = tx.Where("prov_user_id = ?", acceptUser.ProvUserId).First(&truckUserCarInfo).Error
  893. if err != nil {
  894. tx.Rollback()
  895. e.Log.Errorf("获取车辆信息失败: %s", err)
  896. if err == gorm.ErrRecordNotFound {
  897. return errors.New("该司机未绑定车辆,请先绑定车辆!")
  898. }
  899. return errors.New("获取车辆信息失败")
  900. }
  901. for _, innerCode := range c.InnerCodeList {
  902. operationLog33 := model.OperationLog{
  903. BatchNumber: batchNumber,
  904. ProvOperationLog: model.ProvOperationLog{
  905. InnerCode: innerCode,
  906. OptType: "33",
  907. OptUser: allotUser.ProvUserId,
  908. CompanyId: allotUser.ProvUser.CmpCode,
  909. CurrentEnterprise: allotUser.ProvUser.CmpCode,
  910. CurrentStore: allotUser.ProvUser.CmpCode,
  911. Lng: utils.ToString(allotUser.Dept.ProvStore.Lng),
  912. Lat: utils.ToString(allotUser.Dept.ProvStore.Lat),
  913. OptTime: optTime,
  914. },
  915. ControlBy: cModel.ControlBy{
  916. CreateBy: p.UserId,
  917. },
  918. DeptBy: cModel.DeptBy{
  919. DeptId: allotUser.DeptId,
  920. },
  921. }
  922. data = append(data, operationLog33)
  923. gasCylinderStatus := &model.GasCylinderStatus{
  924. InnerCode: innerCode,
  925. UserId: acceptUser.Id,
  926. CompanyId: acceptUser.Dept.Id,
  927. Status: model.GasCylinderStatusWeighty,
  928. ControlBy: cModel.ControlBy{
  929. CreateBy: p.UserId,
  930. },
  931. DeptBy: cModel.DeptBy{
  932. DeptId: acceptUser.DeptId,
  933. },
  934. }
  935. // 司机添加重瓶
  936. err = tx.Where(model.GasCylinderStatus{InnerCode: innerCode, UserId: acceptUser.Id, CompanyId: acceptUser.Dept.Id}).
  937. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
  938. if err != nil {
  939. e.Log.Errorf("db error: %s", err)
  940. return global.CreateFailedErr
  941. }
  942. }
  943. // 删除门店重瓶
  944. err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?",
  945. c.InnerCodeList, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
  946. Delete(&model.GasCylinderStatus{}).Error
  947. if err != nil {
  948. e.Log.Errorf("db error: %s", err)
  949. return global.CreateFailedErr
  950. }
  951. case "016":
  952. // 16 司机将订单退回气站
  953. var truckUserCarInfo model.TruckUserCarInfo
  954. err = tx.Where("prov_user_id = ?", allotUser.ProvUserId).First(&truckUserCarInfo).Error
  955. if err != nil {
  956. tx.Rollback()
  957. e.Log.Errorf("获取车辆信息失败: %s", err)
  958. if err == gorm.ErrRecordNotFound {
  959. return errors.New("该司机未绑定车辆,请先绑定车辆!")
  960. }
  961. return errors.New("获取车辆信息失败")
  962. }
  963. for _, innerCode := range c.InnerCodeList {
  964. // 2、上报气瓶流转信息
  965. operationLog16 := model.OperationLog{
  966. BatchNumber: batchNumber,
  967. ProvOperationLog: model.ProvOperationLog{
  968. InnerCode: innerCode,
  969. OptType: "16",
  970. ObjectUser: allotUser.ProvUserId,
  971. OptUser: allotUser.ProvUserId,
  972. CompanyId: allotUser.ProvUser.CmpCode,
  973. CurrentEnterprise: allotUser.ProvUser.CmpCode,
  974. CurrentStation: acceptUser.Dept.CmpCode,
  975. CurrentTruck: allotUser.ProvUserId,
  976. CurrentMotor: truckUserCarInfo.CarNo,
  977. OptTime: optTime,
  978. },
  979. ControlBy: cModel.ControlBy{
  980. CreateBy: p.UserId,
  981. },
  982. DeptBy: cModel.DeptBy{
  983. DeptId: p.DeptId,
  984. },
  985. }
  986. data = append(data, operationLog16)
  987. gasCylinderStatus := &model.GasCylinderStatus{
  988. InnerCode: innerCode,
  989. UserId: 0,
  990. CompanyId: acceptUser.Dept.Id,
  991. Status: model.GasCylinderStatusWeighty,
  992. ControlBy: cModel.ControlBy{
  993. CreateBy: p.UserId,
  994. },
  995. DeptBy: cModel.DeptBy{
  996. DeptId: acceptUser.DeptId,
  997. },
  998. }
  999. // 气站添加重瓶
  1000. err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", innerCode, acceptUser.Dept.Id).
  1001. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
  1002. if err != nil {
  1003. e.Log.Errorf("db error: %s", err)
  1004. return global.CreateFailedErr
  1005. }
  1006. }
  1007. // 删除司机重瓶
  1008. err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
  1009. c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
  1010. Delete(&model.GasCylinderStatus{}).Error
  1011. if err != nil {
  1012. e.Log.Errorf("db error: %s", err)
  1013. return global.CreateFailedErr
  1014. }
  1015. case "md" + model.GasCylinderStatusScrap, "sj" + model.GasCylinderStatusScrap, "qz" + model.GasCylinderStatusScrap:
  1016. // 不合格 送气员->门店->司机->气站
  1017. // 送气员->门店
  1018. if allotUser.ProvUser.UserType == 3 && allotUser.ProvUser.Isorders == 0 {
  1019. // 送气员到门店 送气员不合格- 门店+
  1020. if acceptUser.ProvUser.UserType == 3 && acceptUser.ProvUser.Isorders == 1 {
  1021. for _, innerCode := range c.InnerCodeList {
  1022. // mdscrap 门店回收报废瓶
  1023. operationLogMdscrap := model.OperationLog{
  1024. BatchNumber: batchNumber,
  1025. ProvOperationLog: model.ProvOperationLog{
  1026. InnerCode: innerCode,
  1027. OptType: c.OptType,
  1028. ObjectUser: acceptUser.ProvUserId,
  1029. OptUser: acceptUser.ProvUserId,
  1030. CompanyId: acceptUser.ProvUser.CmpCode,
  1031. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  1032. CurrentStore: acceptUser.ProvUser.CmpCode,
  1033. Lng: utils.ToString(acceptUser.Dept.ProvStore.Lng),
  1034. Lat: utils.ToString(acceptUser.Dept.ProvStore.Lat),
  1035. OptTime: optTime,
  1036. },
  1037. ControlBy: cModel.ControlBy{
  1038. CreateBy: p.UserId,
  1039. },
  1040. DeptBy: cModel.DeptBy{
  1041. DeptId: p.DeptId,
  1042. },
  1043. }
  1044. data = append(data, operationLogMdscrap)
  1045. gasCylinderStatus := &model.GasCylinderStatus{
  1046. InnerCode: innerCode,
  1047. UserId: 0,
  1048. CompanyId: acceptUser.Dept.Id,
  1049. Status: model.GasCylinderStatusScrap,
  1050. ControlBy: cModel.ControlBy{
  1051. CreateBy: p.UserId,
  1052. },
  1053. DeptBy: cModel.DeptBy{
  1054. DeptId: acceptUser.DeptId,
  1055. },
  1056. }
  1057. // 门店添加报废瓶瓶
  1058. err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", innerCode, acceptUser.Dept.Id).
  1059. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusScrap}).FirstOrCreate(&gasCylinderStatus).Error
  1060. if err != nil {
  1061. e.Log.Errorf("db error: %s", err)
  1062. return global.CreateFailedErr
  1063. }
  1064. }
  1065. // 删除送气员报废瓶瓶
  1066. err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
  1067. c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusScrap).
  1068. Delete(&model.GasCylinderStatus{}).Error
  1069. if err != nil {
  1070. e.Log.Errorf("db error: %s", err)
  1071. return global.CreateFailedErr
  1072. }
  1073. } else {
  1074. err = errors.New("请出示正确的门店回收报废瓶瓶调拨码")
  1075. return err
  1076. }
  1077. } else if allotUser.ProvUser.UserType == 3 && allotUser.ProvUser.Isorders == 1 {
  1078. // 门店到司机 门店- 司机+
  1079. var truckUserCarInfo model.TruckUserCarInfo
  1080. err = tx.Where("prov_user_id = ?", acceptUser.ProvUserId).First(&truckUserCarInfo).Error
  1081. if err != nil {
  1082. tx.Rollback()
  1083. e.Log.Errorf("获取车辆信息失败: %s", err)
  1084. if err == gorm.ErrRecordNotFound {
  1085. return errors.New("该司机未绑定车辆,请先绑定车辆!")
  1086. }
  1087. return errors.New("获取车辆信息失败")
  1088. }
  1089. if acceptUser.ProvUser.UserType == 4 {
  1090. for _, innerCode := range c.InnerCodeList {
  1091. operationLogSjscrap := model.OperationLog{
  1092. BatchNumber: batchNumber,
  1093. ProvOperationLog: model.ProvOperationLog{
  1094. InnerCode: innerCode,
  1095. OptType: c.OptType,
  1096. ObjectUser: acceptUser.ProvUserId,
  1097. OptUser: acceptUser.ProvUserId,
  1098. CompanyId: acceptUser.ProvUser.CmpCode,
  1099. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  1100. CurrentStore: allotUser.ProvUser.CmpCode,
  1101. CurrentTruck: acceptUser.ProvUserId,
  1102. CurrentMotor: truckUserCarInfo.CarNo,
  1103. OptTime: optTime,
  1104. },
  1105. ControlBy: cModel.ControlBy{
  1106. CreateBy: p.UserId,
  1107. },
  1108. DeptBy: cModel.DeptBy{
  1109. DeptId: acceptUser.DeptId,
  1110. },
  1111. }
  1112. data = append(data, operationLogSjscrap)
  1113. gasCylinderStatus := &model.GasCylinderStatus{
  1114. InnerCode: innerCode,
  1115. UserId: acceptUser.Id,
  1116. CompanyId: acceptUser.Dept.Id,
  1117. Status: model.GasCylinderStatusScrap,
  1118. ControlBy: cModel.ControlBy{
  1119. CreateBy: p.UserId,
  1120. },
  1121. DeptBy: cModel.DeptBy{
  1122. DeptId: acceptUser.DeptId,
  1123. },
  1124. }
  1125. // 司机添加报废瓶瓶
  1126. err = tx.Where(model.GasCylinderStatus{InnerCode: innerCode, UserId: acceptUser.Id, CompanyId: acceptUser.Dept.Id}).
  1127. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusScrap}).FirstOrCreate(&gasCylinderStatus).Error
  1128. if err != nil {
  1129. e.Log.Errorf("db error: %s", err)
  1130. return global.CreateFailedErr
  1131. }
  1132. }
  1133. // 删除门店报废瓶瓶
  1134. err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?",
  1135. c.InnerCodeList, allotUser.Dept.Id, model.GasCylinderStatusScrap).
  1136. Delete(&model.GasCylinderStatus{}).Error
  1137. if err != nil {
  1138. e.Log.Errorf("db error: %s", err)
  1139. return global.CreateFailedErr
  1140. }
  1141. } else {
  1142. err = errors.New("请司机出示正确的回收报废瓶瓶调拨码")
  1143. return err
  1144. }
  1145. } else if allotUser.ProvUser.UserType == 4 {
  1146. // 司机给门店
  1147. if acceptUser.ProvUser.UserType == 3 && acceptUser.ProvUser.Isorders == 1 {
  1148. var truckUserCarInfo model.TruckUserCarInfo
  1149. err = tx.Where("prov_user_id = ?", allotUser.ProvUserId).First(&truckUserCarInfo).Error
  1150. if err != nil {
  1151. tx.Rollback()
  1152. e.Log.Errorf("获取车辆信息失败: %s", err)
  1153. if err == gorm.ErrRecordNotFound {
  1154. return errors.New("该司机未绑定车辆,请先绑定车辆!")
  1155. }
  1156. return errors.New("获取车辆信息失败")
  1157. }
  1158. for _, innerCode := range c.InnerCodeList {
  1159. // 司机交付门店
  1160. operationLogMdscrap := model.OperationLog{
  1161. BatchNumber: batchNumber,
  1162. ProvOperationLog: model.ProvOperationLog{
  1163. InnerCode: innerCode,
  1164. OptType: c.OptType,
  1165. OptUser: acceptUser.ProvUserId,
  1166. ObjectUser: acceptUser.ProvUserId,
  1167. CompanyId: acceptUser.ProvUser.CmpCode,
  1168. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  1169. CurrentStore: acceptUser.ProvUser.CmpCode,
  1170. CurrentTruck: acceptUser.ProvUserId,
  1171. CurrentMotor: truckUserCarInfo.CarNo,
  1172. OptTime: optTime,
  1173. },
  1174. ControlBy: cModel.ControlBy{
  1175. CreateBy: p.UserId,
  1176. },
  1177. DeptBy: cModel.DeptBy{
  1178. DeptId: acceptUser.DeptId,
  1179. },
  1180. }
  1181. data = append(data, operationLogMdscrap)
  1182. gasCylinderStatus := &model.GasCylinderStatus{
  1183. InnerCode: innerCode,
  1184. UserId: 0,
  1185. CompanyId: acceptUser.Dept.Id,
  1186. Status: model.GasCylinderStatusScrap,
  1187. ControlBy: cModel.ControlBy{
  1188. CreateBy: p.UserId,
  1189. },
  1190. DeptBy: cModel.DeptBy{
  1191. DeptId: acceptUser.DeptId,
  1192. },
  1193. }
  1194. // 门店添加报废瓶瓶
  1195. err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", innerCode, acceptUser.Dept.Id).
  1196. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusScrap}).FirstOrCreate(&gasCylinderStatus).Error
  1197. if err != nil {
  1198. e.Log.Errorf("db error: %s", err)
  1199. return global.CreateFailedErr
  1200. }
  1201. }
  1202. // 删除司机报废瓶瓶
  1203. err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
  1204. c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusScrap).
  1205. Delete(&model.GasCylinderStatus{}).Error
  1206. if err != nil {
  1207. e.Log.Errorf("db error: %s", err)
  1208. return global.CreateFailedErr
  1209. }
  1210. } else if acceptUser.ProvUser.UserType == 5 && acceptUser.ProvUser.Isorders == 0 {
  1211. // 司机到气站 司机- 气站+
  1212. var truckUserCarInfo model.TruckUserCarInfo
  1213. err = tx.Where("prov_user_id = ?", allotUser.ProvUserId).First(&truckUserCarInfo).Error
  1214. if err != nil {
  1215. tx.Rollback()
  1216. e.Log.Errorf("获取车辆信息失败: %s", err)
  1217. if err == gorm.ErrRecordNotFound {
  1218. return errors.New("该司机未绑定车辆,请先绑定车辆!")
  1219. }
  1220. return errors.New("获取车辆信息失败")
  1221. }
  1222. for _, innerCode := range c.InnerCodeList {
  1223. operationLogQzscrap := model.OperationLog{
  1224. BatchNumber: batchNumber,
  1225. ProvOperationLog: model.ProvOperationLog{
  1226. InnerCode: innerCode,
  1227. OptType: c.OptType,
  1228. ObjectUser: acceptUser.ProvUserId,
  1229. OptUser: acceptUser.ProvUserId,
  1230. CompanyId: acceptUser.ProvUser.CmpCode,
  1231. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  1232. CurrentStation: acceptUser.ProvUser.CmpCode,
  1233. Lng: utils.ToString(acceptUser.Dept.ProvStore.Lng),
  1234. Lat: utils.ToString(acceptUser.Dept.ProvStore.Lat),
  1235. OptTime: optTime,
  1236. },
  1237. ControlBy: cModel.ControlBy{
  1238. CreateBy: p.UserId,
  1239. },
  1240. DeptBy: cModel.DeptBy{
  1241. DeptId: p.DeptId,
  1242. },
  1243. }
  1244. data = append(data, operationLogQzscrap)
  1245. gasCylinderStatus := &model.GasCylinderStatus{
  1246. InnerCode: innerCode,
  1247. UserId: 0,
  1248. CompanyId: acceptUser.Dept.Id,
  1249. Status: model.GasCylinderStatusScrap,
  1250. ControlBy: cModel.ControlBy{
  1251. CreateBy: p.UserId,
  1252. },
  1253. DeptBy: cModel.DeptBy{
  1254. DeptId: acceptUser.DeptId,
  1255. },
  1256. }
  1257. // 气站添加报废瓶瓶
  1258. err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", innerCode, acceptUser.Dept.Id).
  1259. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusScrap}).FirstOrCreate(&gasCylinderStatus).Error
  1260. if err != nil {
  1261. e.Log.Errorf("db error: %s", err)
  1262. return global.CreateFailedErr
  1263. }
  1264. }
  1265. // 删除司机报废瓶瓶
  1266. err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
  1267. c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusScrap).
  1268. Delete(&model.GasCylinderStatus{}).Error
  1269. if err != nil {
  1270. e.Log.Errorf("db error: %s", err)
  1271. return global.CreateFailedErr
  1272. }
  1273. } else {
  1274. err = errors.New("请门店/气站出示正确的回收报废瓶瓶调拨码")
  1275. return err
  1276. }
  1277. } else if allotUser.ProvUser.UserType == 5 {
  1278. // 气站到司机
  1279. if acceptUser.ProvUser.UserType == 4 && acceptUser.ProvUser.Isorders == 0 {
  1280. var truckUserCarInfo model.TruckUserCarInfo
  1281. err = tx.Where("prov_user_id = ?", acceptUser.ProvUserId).First(&truckUserCarInfo).Error
  1282. if err != nil {
  1283. tx.Rollback()
  1284. e.Log.Errorf("获取车辆信息失败: %s", err)
  1285. if err == gorm.ErrRecordNotFound {
  1286. return errors.New("该司机未绑定车辆,请先绑定车辆!")
  1287. }
  1288. return errors.New("获取车辆信息失败")
  1289. }
  1290. for _, innerCode := range c.InnerCodeList {
  1291. operationLogSjscrap := model.OperationLog{
  1292. BatchNumber: batchNumber,
  1293. ProvOperationLog: model.ProvOperationLog{
  1294. InnerCode: innerCode,
  1295. OptType: c.OptType,
  1296. OptUser: acceptUser.ProvUserId,
  1297. CompanyId: acceptUser.ProvUser.CmpCode,
  1298. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  1299. CurrentStation: allotUser.ProvUser.CmpCode,
  1300. CurrentTruck: acceptUser.ProvUserId,
  1301. CurrentMotor: truckUserCarInfo.CarNo,
  1302. OptTime: optTime,
  1303. },
  1304. ControlBy: cModel.ControlBy{
  1305. CreateBy: p.UserId,
  1306. },
  1307. DeptBy: cModel.DeptBy{
  1308. DeptId: acceptUser.DeptId,
  1309. },
  1310. }
  1311. data = append(data, operationLogSjscrap)
  1312. gasCylinderStatus := &model.GasCylinderStatus{
  1313. InnerCode: innerCode,
  1314. UserId: acceptUser.Id,
  1315. CompanyId: acceptUser.Dept.Id,
  1316. Status: model.GasCylinderStatusScrap,
  1317. ControlBy: cModel.ControlBy{
  1318. CreateBy: p.UserId,
  1319. },
  1320. DeptBy: cModel.DeptBy{
  1321. DeptId: acceptUser.DeptId,
  1322. },
  1323. }
  1324. // 司机添加报废瓶瓶
  1325. err = tx.Where(model.GasCylinderStatus{InnerCode: innerCode, UserId: acceptUser.Id, CompanyId: acceptUser.Dept.Id}).
  1326. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusScrap}).FirstOrCreate(&gasCylinderStatus).Error
  1327. if err != nil {
  1328. e.Log.Errorf("db error: %s", err)
  1329. return global.CreateFailedErr
  1330. }
  1331. }
  1332. // 删除气站报废瓶瓶
  1333. err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?",
  1334. c.InnerCodeList, allotUser.Dept.Id, model.GasCylinderStatusScrap).
  1335. Delete(&model.GasCylinderStatus{}).Error
  1336. if err != nil {
  1337. e.Log.Errorf("db error: %s", err)
  1338. return global.CreateFailedErr
  1339. }
  1340. } else {
  1341. err = errors.New("请司机出示正确的回收报废瓶瓶调拨码")
  1342. return err
  1343. }
  1344. }
  1345. case "md" + model.GasCylinderStatusExtended, "sj" + model.GasCylinderStatusExtended, "qz" + model.GasCylinderStatusExtended:
  1346. // 不合格 送气员->门店->司机->气站
  1347. // 送气员->门店
  1348. if allotUser.ProvUser.UserType == 3 && allotUser.ProvUser.Isorders == 0 {
  1349. // 送气员到门店 送气员不合格- 门店+
  1350. if acceptUser.ProvUser.UserType == 3 && acceptUser.ProvUser.Isorders == 1 {
  1351. for _, innerCode := range c.InnerCodeList {
  1352. // mdscrap 门店回收报废瓶
  1353. operationLogMdextended := model.OperationLog{
  1354. BatchNumber: batchNumber,
  1355. ProvOperationLog: model.ProvOperationLog{
  1356. InnerCode: innerCode,
  1357. OptType: c.OptType,
  1358. ObjectUser: acceptUser.ProvUserId,
  1359. OptUser: acceptUser.ProvUserId,
  1360. CompanyId: acceptUser.ProvUser.CmpCode,
  1361. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  1362. CurrentStore: acceptUser.ProvUser.CmpCode,
  1363. Lng: utils.ToString(acceptUser.Dept.ProvStore.Lng),
  1364. Lat: utils.ToString(acceptUser.Dept.ProvStore.Lat),
  1365. OptTime: optTime,
  1366. },
  1367. ControlBy: cModel.ControlBy{
  1368. CreateBy: p.UserId,
  1369. },
  1370. DeptBy: cModel.DeptBy{
  1371. DeptId: p.DeptId,
  1372. },
  1373. }
  1374. data = append(data, operationLogMdextended)
  1375. gasCylinderStatus := &model.GasCylinderStatus{
  1376. InnerCode: innerCode,
  1377. UserId: 0,
  1378. CompanyId: acceptUser.Dept.Id,
  1379. Status: model.GasCylinderStatusExtended,
  1380. ControlBy: cModel.ControlBy{
  1381. CreateBy: p.UserId,
  1382. },
  1383. DeptBy: cModel.DeptBy{
  1384. DeptId: acceptUser.DeptId,
  1385. },
  1386. }
  1387. // 门店添加超期瓶
  1388. err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", innerCode, acceptUser.Dept.Id).
  1389. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusExtended}).FirstOrCreate(&gasCylinderStatus).Error
  1390. if err != nil {
  1391. e.Log.Errorf("db error: %s", err)
  1392. return global.CreateFailedErr
  1393. }
  1394. }
  1395. // 删除送气员超期瓶
  1396. err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
  1397. c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusExtended).
  1398. Delete(&model.GasCylinderStatus{}).Error
  1399. if err != nil {
  1400. e.Log.Errorf("db error: %s", err)
  1401. return global.CreateFailedErr
  1402. }
  1403. } else {
  1404. err = errors.New("请出示正确的门店回收超期瓶调拨码")
  1405. return err
  1406. }
  1407. } else if allotUser.ProvUser.UserType == 3 && allotUser.ProvUser.Isorders == 1 {
  1408. // 门店到司机 门店- 司机+
  1409. if acceptUser.ProvUser.UserType == 4 {
  1410. var truckUserCarInfo model.TruckUserCarInfo
  1411. err = tx.Where("prov_user_id = ?", acceptUser.ProvUserId).First(&truckUserCarInfo).Error
  1412. if err != nil {
  1413. tx.Rollback()
  1414. e.Log.Errorf("获取车辆信息失败: %s", err)
  1415. if err == gorm.ErrRecordNotFound {
  1416. return errors.New("该司机未绑定车辆,请先绑定车辆!")
  1417. }
  1418. return errors.New("获取车辆信息失败")
  1419. }
  1420. for _, innerCode := range c.InnerCodeList {
  1421. operationLogSjextended := model.OperationLog{
  1422. BatchNumber: batchNumber,
  1423. ProvOperationLog: model.ProvOperationLog{
  1424. InnerCode: innerCode,
  1425. OptType: c.OptType,
  1426. ObjectUser: acceptUser.ProvUserId,
  1427. OptUser: acceptUser.ProvUserId,
  1428. CompanyId: acceptUser.ProvUser.CmpCode,
  1429. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  1430. CurrentStore: allotUser.ProvUser.CmpCode,
  1431. CurrentTruck: acceptUser.ProvUserId,
  1432. CurrentMotor: truckUserCarInfo.CarNo,
  1433. OptTime: optTime,
  1434. },
  1435. ControlBy: cModel.ControlBy{
  1436. CreateBy: p.UserId,
  1437. },
  1438. DeptBy: cModel.DeptBy{
  1439. DeptId: acceptUser.DeptId,
  1440. },
  1441. }
  1442. data = append(data, operationLogSjextended)
  1443. gasCylinderStatus := &model.GasCylinderStatus{
  1444. InnerCode: innerCode,
  1445. UserId: acceptUser.Id,
  1446. CompanyId: acceptUser.Dept.Id,
  1447. Status: model.GasCylinderStatusExtended,
  1448. ControlBy: cModel.ControlBy{
  1449. CreateBy: p.UserId,
  1450. },
  1451. DeptBy: cModel.DeptBy{
  1452. DeptId: acceptUser.DeptId,
  1453. },
  1454. }
  1455. // 司机添加超期瓶
  1456. err = tx.Where(model.GasCylinderStatus{InnerCode: innerCode, UserId: acceptUser.Id, CompanyId: acceptUser.Dept.Id}).
  1457. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusExtended}).FirstOrCreate(&gasCylinderStatus).Error
  1458. if err != nil {
  1459. e.Log.Errorf("db error: %s", err)
  1460. return global.CreateFailedErr
  1461. }
  1462. }
  1463. // 删除门店超期瓶
  1464. err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?",
  1465. c.InnerCodeList, allotUser.Dept.Id, model.GasCylinderStatusExtended).
  1466. Delete(&model.GasCylinderStatus{}).Error
  1467. if err != nil {
  1468. e.Log.Errorf("db error: %s", err)
  1469. return global.CreateFailedErr
  1470. }
  1471. } else {
  1472. err = errors.New("请司机出示正确的回收超期瓶调拨码")
  1473. return err
  1474. }
  1475. } else if allotUser.ProvUser.UserType == 4 {
  1476. // 司机给门店
  1477. if acceptUser.ProvUser.UserType == 3 && acceptUser.ProvUser.Isorders == 1 {
  1478. var truckUserCarInfo model.TruckUserCarInfo
  1479. err = tx.Where("prov_user_id = ?", allotUser.ProvUserId).First(&truckUserCarInfo).Error
  1480. if err != nil {
  1481. tx.Rollback()
  1482. e.Log.Errorf("获取车辆信息失败: %s", err)
  1483. if err == gorm.ErrRecordNotFound {
  1484. return errors.New("该司机未绑定车辆,请先绑定车辆!")
  1485. }
  1486. return errors.New("获取车辆信息失败")
  1487. }
  1488. for _, innerCode := range c.InnerCodeList {
  1489. // 司机交付门店
  1490. operationLogMdextended := model.OperationLog{
  1491. BatchNumber: batchNumber,
  1492. ProvOperationLog: model.ProvOperationLog{
  1493. InnerCode: innerCode,
  1494. OptType: c.OptType,
  1495. OptUser: acceptUser.ProvUserId,
  1496. ObjectUser: acceptUser.ProvUserId,
  1497. CompanyId: acceptUser.ProvUser.CmpCode,
  1498. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  1499. CurrentStore: acceptUser.ProvUser.CmpCode,
  1500. CurrentTruck: acceptUser.ProvUserId,
  1501. CurrentMotor: truckUserCarInfo.CarNo,
  1502. OptTime: optTime,
  1503. },
  1504. ControlBy: cModel.ControlBy{
  1505. CreateBy: p.UserId,
  1506. },
  1507. DeptBy: cModel.DeptBy{
  1508. DeptId: acceptUser.DeptId,
  1509. },
  1510. }
  1511. data = append(data, operationLogMdextended)
  1512. gasCylinderStatus := &model.GasCylinderStatus{
  1513. InnerCode: innerCode,
  1514. UserId: 0,
  1515. CompanyId: acceptUser.Dept.Id,
  1516. Status: model.GasCylinderStatusExtended,
  1517. ControlBy: cModel.ControlBy{
  1518. CreateBy: p.UserId,
  1519. },
  1520. DeptBy: cModel.DeptBy{
  1521. DeptId: acceptUser.DeptId,
  1522. },
  1523. }
  1524. // 门店添加超期瓶
  1525. err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", innerCode, acceptUser.Dept.Id).
  1526. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusExtended}).FirstOrCreate(&gasCylinderStatus).Error
  1527. if err != nil {
  1528. e.Log.Errorf("db error: %s", err)
  1529. return global.CreateFailedErr
  1530. }
  1531. }
  1532. // 删除司机超期瓶
  1533. err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
  1534. c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusExtended).
  1535. Delete(&model.GasCylinderStatus{}).Error
  1536. if err != nil {
  1537. e.Log.Errorf("db error: %s", err)
  1538. return global.CreateFailedErr
  1539. }
  1540. } else if acceptUser.ProvUser.UserType == 5 && acceptUser.ProvUser.Isorders == 0 {
  1541. // 司机到气站 司机- 气站+
  1542. var truckUserCarInfo model.TruckUserCarInfo
  1543. err = tx.Where("prov_user_id = ?", allotUser.ProvUserId).First(&truckUserCarInfo).Error
  1544. if err != nil {
  1545. tx.Rollback()
  1546. e.Log.Errorf("获取车辆信息失败: %s", err)
  1547. if err == gorm.ErrRecordNotFound {
  1548. return errors.New("该司机未绑定车辆,请先绑定车辆!")
  1549. }
  1550. return errors.New("获取车辆信息失败")
  1551. }
  1552. for _, innerCode := range c.InnerCodeList {
  1553. operationLogQzextended := model.OperationLog{
  1554. BatchNumber: batchNumber,
  1555. ProvOperationLog: model.ProvOperationLog{
  1556. InnerCode: innerCode,
  1557. OptType: c.OptType,
  1558. ObjectUser: acceptUser.ProvUserId,
  1559. OptUser: acceptUser.ProvUserId,
  1560. CompanyId: acceptUser.ProvUser.CmpCode,
  1561. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  1562. CurrentStation: acceptUser.ProvUser.CmpCode,
  1563. Lng: utils.ToString(acceptUser.Dept.ProvStore.Lng),
  1564. Lat: utils.ToString(acceptUser.Dept.ProvStore.Lat),
  1565. OptTime: optTime,
  1566. },
  1567. ControlBy: cModel.ControlBy{
  1568. CreateBy: p.UserId,
  1569. },
  1570. DeptBy: cModel.DeptBy{
  1571. DeptId: p.DeptId,
  1572. },
  1573. }
  1574. data = append(data, operationLogQzextended)
  1575. gasCylinderStatus := &model.GasCylinderStatus{
  1576. InnerCode: innerCode,
  1577. UserId: 0,
  1578. CompanyId: acceptUser.Dept.Id,
  1579. Status: model.GasCylinderStatusExtended,
  1580. ControlBy: cModel.ControlBy{
  1581. CreateBy: p.UserId,
  1582. },
  1583. DeptBy: cModel.DeptBy{
  1584. DeptId: acceptUser.DeptId,
  1585. },
  1586. }
  1587. // 气站添加超期瓶
  1588. err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", innerCode, acceptUser.Dept.Id).
  1589. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusExtended}).FirstOrCreate(&gasCylinderStatus).Error
  1590. if err != nil {
  1591. e.Log.Errorf("db error: %s", err)
  1592. return global.CreateFailedErr
  1593. }
  1594. }
  1595. // 删除司机超期瓶
  1596. err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
  1597. c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusExtended).
  1598. Delete(&model.GasCylinderStatus{}).Error
  1599. if err != nil {
  1600. e.Log.Errorf("db error: %s", err)
  1601. return global.CreateFailedErr
  1602. }
  1603. } else {
  1604. err = errors.New("请门店/气站出示正确的回收超期瓶调拨码")
  1605. return err
  1606. }
  1607. } else if allotUser.ProvUser.UserType == 5 {
  1608. // 气站到司机
  1609. if acceptUser.ProvUser.UserType == 4 && acceptUser.ProvUser.Isorders == 0 {
  1610. var truckUserCarInfo model.TruckUserCarInfo
  1611. err = tx.Where("prov_user_id = ?", acceptUser.ProvUserId).First(&truckUserCarInfo).Error
  1612. if err != nil {
  1613. tx.Rollback()
  1614. e.Log.Errorf("获取车辆信息失败: %s", err)
  1615. if err == gorm.ErrRecordNotFound {
  1616. return errors.New("该司机未绑定车辆,请先绑定车辆!")
  1617. }
  1618. return errors.New("获取车辆信息失败")
  1619. }
  1620. for _, innerCode := range c.InnerCodeList {
  1621. operationLogSjextended := model.OperationLog{
  1622. BatchNumber: batchNumber,
  1623. ProvOperationLog: model.ProvOperationLog{
  1624. InnerCode: innerCode,
  1625. OptType: c.OptType,
  1626. OptUser: acceptUser.ProvUserId,
  1627. CompanyId: acceptUser.ProvUser.CmpCode,
  1628. CurrentEnterprise: acceptUser.ProvUser.CmpCode,
  1629. CurrentStation: allotUser.ProvUser.CmpCode,
  1630. CurrentTruck: acceptUser.ProvUserId,
  1631. CurrentMotor: truckUserCarInfo.CarNo,
  1632. OptTime: optTime,
  1633. },
  1634. ControlBy: cModel.ControlBy{
  1635. CreateBy: p.UserId,
  1636. },
  1637. DeptBy: cModel.DeptBy{
  1638. DeptId: acceptUser.DeptId,
  1639. },
  1640. }
  1641. data = append(data, operationLogSjextended)
  1642. gasCylinderStatus := &model.GasCylinderStatus{
  1643. InnerCode: innerCode,
  1644. UserId: acceptUser.Id,
  1645. CompanyId: acceptUser.Dept.Id,
  1646. Status: model.GasCylinderStatusExtended,
  1647. ControlBy: cModel.ControlBy{
  1648. CreateBy: p.UserId,
  1649. },
  1650. DeptBy: cModel.DeptBy{
  1651. DeptId: acceptUser.DeptId,
  1652. },
  1653. }
  1654. // 司机添加超期瓶
  1655. err = tx.Where(model.GasCylinderStatus{InnerCode: innerCode, UserId: acceptUser.Id, CompanyId: acceptUser.Dept.Id}).
  1656. Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusExtended}).FirstOrCreate(&gasCylinderStatus).Error
  1657. if err != nil {
  1658. e.Log.Errorf("db error: %s", err)
  1659. return global.CreateFailedErr
  1660. }
  1661. }
  1662. // 删除气站超期瓶
  1663. err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?",
  1664. c.InnerCodeList, allotUser.Dept.Id, model.GasCylinderStatusExtended).
  1665. Delete(&model.GasCylinderStatus{}).Error
  1666. if err != nil {
  1667. e.Log.Errorf("db error: %s", err)
  1668. return global.CreateFailedErr
  1669. }
  1670. } else {
  1671. err = errors.New("请司机出示正确的回收超期瓶调拨码")
  1672. return err
  1673. }
  1674. }
  1675. }
  1676. provList := make([]model.ProvOperationLog, 0)
  1677. for _, v := range data {
  1678. provList = append(provList, v.GenProvOperationLog())
  1679. }
  1680. // TODO 同步省平台 1.1.1.22 批量新增操作记录
  1681. if len(data) > 0 {
  1682. err = tx.Create(&data).Error
  1683. if err != nil {
  1684. e.Log.Errorf("db error: %s", err)
  1685. return errors.New("添加流转步骤失败")
  1686. }
  1687. }
  1688. // 更新钢瓶最新流转步骤时间
  1689. err = tx.Model(&model.GasCylinder{}).Where("inner_code in (?) ", c.InnerCodeList).
  1690. Updates(map[string]interface{}{
  1691. "last_operation_time": time.Now(),
  1692. }).Error
  1693. if err != nil {
  1694. e.Log.Errorf("db error: %s", err)
  1695. return errors.New("更新钢瓶最新流转步骤时间失败")
  1696. }
  1697. return nil
  1698. }
  1699. func (e *GasCylinderAllot) VerifyGasCylinderStatus(optType string, acceptUserId, allotUserId int, innerCodeList []string) error {
  1700. acceptUser, err := model.GetUserCode(acceptUserId)
  1701. if err != nil {
  1702. e.Log.Errorf("db error: %s", err)
  1703. return errors.New("查询接收人信息失败!")
  1704. }
  1705. allotUser, err := model.GetUserCode(allotUserId)
  1706. if err != nil {
  1707. e.Log.Errorf("db error: %s", err)
  1708. return errors.New("查询调拨人信息失败!")
  1709. }
  1710. switch optType {
  1711. case "25":
  1712. // 25送气员领重瓶 37 门店重瓶出库
  1713. for _, innerCode := range innerCodeList {
  1714. // 查询门店重瓶
  1715. var gsc model.GasCylinderStatus
  1716. err = e.Orm.Where("inner_code = ? and user_id = 0 and company_id = ? and status = ?", innerCode, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
  1717. Preload("Company").
  1718. First(&gsc).Error
  1719. if err != nil {
  1720. e.Log.Errorf("db error: %s", err)
  1721. if errors.Is(err, gorm.ErrRecordNotFound) {
  1722. return errors.New(fmt.Sprintf("门店【%s】重瓶%s不存在", allotUser.Dept.Name, innerCode))
  1723. }
  1724. return errors.New(fmt.Sprintf("查询门店重瓶失败"))
  1725. }
  1726. }
  1727. case "21":
  1728. // 21门店回收空瓶 27送气员回收空瓶
  1729. for _, innerCode := range innerCodeList {
  1730. // 查询送气员空瓶
  1731. var gsc model.GasCylinderStatus
  1732. err = e.Orm.Where("inner_code = ? and user_id = ? and company_id = ? and status = ?", innerCode, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusEmpty).
  1733. Preload("User").
  1734. First(&gsc).Error
  1735. if err != nil {
  1736. e.Log.Errorf("db error: %s", err)
  1737. if errors.Is(err, gorm.ErrRecordNotFound) {
  1738. return errors.New(fmt.Sprintf("送气员【%s】空瓶%s不存在", allotUser.NickName, innerCode))
  1739. }
  1740. return errors.New(fmt.Sprintf("查询送气员空瓶失败"))
  1741. }
  1742. }
  1743. case "11":
  1744. // 10 门店空瓶出库 11 司机确认空瓶装车
  1745. for _, innerCode := range innerCodeList {
  1746. // 查询门店空瓶
  1747. var gsc model.GasCylinderStatus
  1748. err = e.Orm.Where("inner_code = ? and user_id = 0 and company_id = ? and status = ?", innerCode, allotUser.Dept.Id, model.GasCylinderStatusEmpty).
  1749. Preload("Company").
  1750. First(&gsc).Error
  1751. if err != nil {
  1752. e.Log.Errorf("db error: %s", err)
  1753. if errors.Is(err, gorm.ErrRecordNotFound) {
  1754. return errors.New(fmt.Sprintf("门店【%s】空瓶%s不存在", allotUser.Dept.Name, innerCode))
  1755. }
  1756. return errors.New(fmt.Sprintf("查询门店空瓶失败"))
  1757. }
  1758. }
  1759. case "13":
  1760. // 12 司机运输空瓶到达气站 13 气站确认空瓶到达气站
  1761. for _, innerCode := range innerCodeList {
  1762. // 查询司机空瓶
  1763. var gsc model.GasCylinderStatus
  1764. err = e.Orm.Where("inner_code = ? and user_id = ? and company_id = ? and status = ?", innerCode, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusEmpty).
  1765. Preload("User").
  1766. First(&gsc).Error
  1767. if err != nil {
  1768. e.Log.Errorf("db error: %s", err)
  1769. if errors.Is(err, gorm.ErrRecordNotFound) {
  1770. return errors.New(fmt.Sprintf("司机【%s】空瓶%s不存在", allotUser.NickName, innerCode))
  1771. }
  1772. return errors.New(fmt.Sprintf("查询司机空瓶失败"))
  1773. }
  1774. }
  1775. case "17":
  1776. // 15 气站重瓶出库 17 司机确认重瓶从气站出库
  1777. for _, innerCode := range innerCodeList {
  1778. // 查询气站重瓶
  1779. var gsc model.GasCylinderStatus
  1780. err = e.Orm.Where("inner_code = ? and user_id = 0 and company_id = ? and status = ?", innerCode, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
  1781. Preload("Company").
  1782. First(&gsc).Error
  1783. if err != nil {
  1784. e.Log.Errorf("db error: %s", err)
  1785. if errors.Is(err, gorm.ErrRecordNotFound) {
  1786. return errors.New(fmt.Sprintf("气站【%s】重瓶%s不存在", allotUser.Dept.Name, innerCode))
  1787. }
  1788. return errors.New(fmt.Sprintf("查询气站重瓶失败"))
  1789. }
  1790. }
  1791. case "31":
  1792. // 19 司机交付门店 31 门店确认重瓶卸货入库
  1793. for _, innerCode := range innerCodeList {
  1794. // 查询司机重瓶
  1795. var gsc model.GasCylinderStatus
  1796. err = e.Orm.Where("inner_code in = ? and user_id = ? and company_id = ? and status = ?",
  1797. innerCode, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
  1798. Preload("User").
  1799. First(&gsc).Error
  1800. if err != nil {
  1801. e.Log.Errorf("db error: %s", err)
  1802. if errors.Is(err, gorm.ErrRecordNotFound) {
  1803. return errors.New(fmt.Sprintf("司机【%s】重瓶%s不存在", allotUser.NickName, innerCode))
  1804. }
  1805. return errors.New(fmt.Sprintf("查询司机重瓶失败"))
  1806. }
  1807. }
  1808. case "35":
  1809. // 35 门店确认未配送重瓶返库
  1810. for _, innerCode := range innerCodeList {
  1811. // 查询送气员重瓶
  1812. var gsc model.GasCylinderStatus
  1813. err = e.Orm.Where("inner_code in = ? and user_id = ? and company_id = ? and status = ?",
  1814. innerCode, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
  1815. Preload("User").
  1816. First(&gsc).Error
  1817. if err != nil {
  1818. e.Log.Errorf("db error: %s", err)
  1819. if errors.Is(err, gorm.ErrRecordNotFound) {
  1820. return errors.New(fmt.Sprintf("送气员【%s】重瓶%s不存在", allotUser.NickName, innerCode))
  1821. }
  1822. return errors.New(fmt.Sprintf("查询送气员重瓶失败"))
  1823. }
  1824. }
  1825. case "033":
  1826. // 33 门店将重瓶退回司机
  1827. for _, innerCode := range innerCodeList {
  1828. // 查询门店重瓶
  1829. var gsc model.GasCylinderStatus
  1830. err = e.Orm.Where("inner_code = ? and user_id = 0 and company_id = ? and status = ?",
  1831. innerCode, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
  1832. Preload("Company").
  1833. First(&gsc).Error
  1834. if err != nil {
  1835. e.Log.Errorf("db error: %s", err)
  1836. if errors.Is(err, gorm.ErrRecordNotFound) {
  1837. return errors.New(fmt.Sprintf("门店【%s】重瓶%s不存在", allotUser.Dept.Name, innerCode))
  1838. }
  1839. return errors.New(fmt.Sprintf("查询门店重瓶失败"))
  1840. }
  1841. }
  1842. case "016":
  1843. // 16 司机将订单退回气站
  1844. for _, innerCode := range innerCodeList {
  1845. // 查询司机重瓶
  1846. var gsc model.GasCylinderStatus
  1847. err = e.Orm.Where("inner_code = ? and user_id = ? and company_id = ? and status = ?",
  1848. innerCode, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
  1849. Preload("User").
  1850. First(&gsc).Error
  1851. if err != nil {
  1852. e.Log.Errorf("db error: %s", err)
  1853. if errors.Is(err, gorm.ErrRecordNotFound) {
  1854. return errors.New(fmt.Sprintf("司机【%s】重瓶%s不存在", allotUser.NickName, innerCode))
  1855. }
  1856. return errors.New(fmt.Sprintf("查询司机重瓶失败"))
  1857. }
  1858. }
  1859. case "md" + model.GasCylinderStatusScrap, "sj" + model.GasCylinderStatusScrap, "qz" + model.GasCylinderStatusScrap:
  1860. // 不合格 送气员->门店->司机->气站
  1861. // 送气员->门店
  1862. if allotUser.ProvUser.UserType == 3 && allotUser.ProvUser.Isorders == 0 {
  1863. // 送气员到门店 送气员不合格- 门店+
  1864. if acceptUser.ProvUser.UserType == 3 && acceptUser.ProvUser.Isorders == 1 {
  1865. for _, innerCode := range innerCodeList {
  1866. // 查询送气员报废瓶
  1867. var gsc model.GasCylinderStatus
  1868. err = e.Orm.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
  1869. innerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusScrap).
  1870. Preload("User").
  1871. First(&gsc).Error
  1872. if err != nil {
  1873. e.Log.Errorf("db error: %s", err)
  1874. if errors.Is(err, gorm.ErrRecordNotFound) {
  1875. return errors.New(fmt.Sprintf("送气员【%s】报废瓶%s不存在", allotUser.NickName, innerCode))
  1876. }
  1877. return errors.New(fmt.Sprintf("查询送气员报废瓶失败"))
  1878. }
  1879. }
  1880. }
  1881. } else if allotUser.ProvUser.UserType == 3 && allotUser.ProvUser.Isorders == 1 {
  1882. // 门店到司机 门店- 司机+
  1883. if acceptUser.ProvUser.UserType == 4 {
  1884. for _, innerCode := range innerCodeList {
  1885. // 查询门店报废瓶
  1886. var gsc model.GasCylinderStatus
  1887. err = e.Orm.Where("inner_code = ? and user_id = 0 and company_id = ? and status = ?",
  1888. innerCode, allotUser.Dept.Id, model.GasCylinderStatusScrap).
  1889. Preload("Company").
  1890. First(&gsc).Error
  1891. if err != nil {
  1892. e.Log.Errorf("db error: %s", err)
  1893. if errors.Is(err, gorm.ErrRecordNotFound) {
  1894. return errors.New(fmt.Sprintf("门店【%s】报废瓶%s不存在", allotUser.Dept.Name, innerCode))
  1895. }
  1896. return errors.New(fmt.Sprintf("查询门店报废瓶失败"))
  1897. }
  1898. }
  1899. }
  1900. } else if allotUser.ProvUser.UserType == 4 {
  1901. // 司机给门店
  1902. if acceptUser.ProvUser.UserType == 3 && acceptUser.ProvUser.Isorders == 1 {
  1903. for _, innerCode := range innerCodeList {
  1904. // 查询司机报废瓶
  1905. var gsc model.GasCylinderStatus
  1906. err = e.Orm.Where("inner_code = ? and user_id = ? and company_id = ? and status = ?",
  1907. innerCode, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusScrap).
  1908. Preload("User").
  1909. First(&gsc).Error
  1910. if err != nil {
  1911. e.Log.Errorf("db error: %s", err)
  1912. if errors.Is(err, gorm.ErrRecordNotFound) {
  1913. return errors.New(fmt.Sprintf("司机【%s】报废瓶%s不存在", allotUser.NickName, innerCode))
  1914. }
  1915. return errors.New(fmt.Sprintf("查询司机报废瓶失败"))
  1916. }
  1917. }
  1918. } else if acceptUser.ProvUser.UserType == 5 && acceptUser.ProvUser.Isorders == 0 {
  1919. // 司机到气站 司机- 气站+
  1920. for _, innerCode := range innerCodeList {
  1921. // 查询司机报废瓶
  1922. var gsc model.GasCylinderStatus
  1923. err = e.Orm.Where("inner_code = ? and user_id = ? and company_id = ? and status = ?",
  1924. innerCode, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusScrap).
  1925. Preload("User").
  1926. First(&gsc).Error
  1927. if err != nil {
  1928. e.Log.Errorf("db error: %s", err)
  1929. if errors.Is(err, gorm.ErrRecordNotFound) {
  1930. return errors.New(fmt.Sprintf("司机【%s】报废瓶%s不存在", allotUser.NickName, innerCode))
  1931. }
  1932. return errors.New(fmt.Sprintf("查询司机报废瓶失败"))
  1933. }
  1934. }
  1935. }
  1936. } else if allotUser.ProvUser.UserType == 5 {
  1937. // 气站到司机
  1938. if acceptUser.ProvUser.UserType == 4 && acceptUser.ProvUser.Isorders == 0 {
  1939. for _, innerCode := range innerCodeList {
  1940. // 查询气站报废瓶
  1941. var gsc model.GasCylinderStatus
  1942. err = e.Orm.Where("inner_code = ? and user_id = 0 and company_id = ? and status = ?",
  1943. innerCode, allotUser.Dept.Id, model.GasCylinderStatusScrap).
  1944. Preload("Company").
  1945. First(&gsc).Error
  1946. if err != nil {
  1947. e.Log.Errorf("db error: %s", err)
  1948. if errors.Is(err, gorm.ErrRecordNotFound) {
  1949. return errors.New(fmt.Sprintf("气站【%s】报废瓶%s不存在", allotUser.Dept.Name, innerCode))
  1950. }
  1951. return errors.New(fmt.Sprintf("查询气站报废瓶失败"))
  1952. }
  1953. }
  1954. }
  1955. }
  1956. case "md" + model.GasCylinderStatusExtended, "sj" + model.GasCylinderStatusExtended, "qz" + model.GasCylinderStatusExtended:
  1957. // 不合格 送气员->门店->司机->气站
  1958. // 送气员->门店
  1959. if allotUser.ProvUser.UserType == 3 && allotUser.ProvUser.Isorders == 0 {
  1960. // 送气员到门店 送气员不合格- 门店+
  1961. if acceptUser.ProvUser.UserType == 3 && acceptUser.ProvUser.Isorders == 1 {
  1962. for _, innerCode := range innerCodeList {
  1963. // 查询送气员超期瓶
  1964. var gsc model.GasCylinderStatus
  1965. err = e.Orm.Where("inner_code = ? and user_id = ? and company_id = ? and status = ?",
  1966. innerCode, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusExtended).
  1967. Preload("User").
  1968. First(&gsc).Error
  1969. if err != nil {
  1970. e.Log.Errorf("db error: %s", err)
  1971. if errors.Is(err, gorm.ErrRecordNotFound) {
  1972. return errors.New(fmt.Sprintf("送气员【%s】超期瓶%s不存在", allotUser.NickName, innerCode))
  1973. }
  1974. return errors.New(fmt.Sprintf("查询送气员超期瓶失败"))
  1975. }
  1976. }
  1977. }
  1978. } else if allotUser.ProvUser.UserType == 3 && allotUser.ProvUser.Isorders == 1 {
  1979. // 门店到司机 门店- 司机+
  1980. if acceptUser.ProvUser.UserType == 4 {
  1981. for _, innerCode := range innerCodeList {
  1982. // 查询门店超期瓶
  1983. var gsc model.GasCylinderStatus
  1984. err = e.Orm.Where("inner_code = ? and user_id = 0 and company_id = ? and status = ?",
  1985. innerCode, allotUser.Dept.Id, model.GasCylinderStatusExtended).
  1986. Preload("Company").
  1987. First(&gsc).Error
  1988. if err != nil {
  1989. e.Log.Errorf("db error: %s", err)
  1990. if errors.Is(err, gorm.ErrRecordNotFound) {
  1991. return errors.New(fmt.Sprintf("门店【%s】超期瓶%s不存在", allotUser.Dept.Name, innerCode))
  1992. }
  1993. return errors.New(fmt.Sprintf("查询门店超期瓶失败"))
  1994. }
  1995. }
  1996. }
  1997. } else if allotUser.ProvUser.UserType == 4 {
  1998. // 司机给门店
  1999. if acceptUser.ProvUser.UserType == 3 && acceptUser.ProvUser.Isorders == 1 {
  2000. for _, innerCode := range innerCodeList {
  2001. // 查询司机超期瓶
  2002. var gsc model.GasCylinderStatus
  2003. err = e.Orm.Where("inner_code = ? and user_id = ? and company_id = ? and status = ?",
  2004. innerCode, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusExtended).
  2005. Preload("User").
  2006. First(&gsc).Error
  2007. if err != nil {
  2008. e.Log.Errorf("db error: %s", err)
  2009. if errors.Is(err, gorm.ErrRecordNotFound) {
  2010. return errors.New(fmt.Sprintf("司机【%s】超期瓶%s不存在", allotUser.NickName, innerCode))
  2011. }
  2012. return errors.New(fmt.Sprintf("查询司机超期瓶失败"))
  2013. }
  2014. }
  2015. } else if acceptUser.ProvUser.UserType == 5 && acceptUser.ProvUser.Isorders == 0 {
  2016. // 司机到气站 司机- 气站+
  2017. for _, innerCode := range innerCodeList {
  2018. // 查询司机超期瓶
  2019. var gsc model.GasCylinderStatus
  2020. err = e.Orm.Where("inner_code = ? and user_id = ? and company_id = ? and status = ?",
  2021. innerCode, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusExtended).
  2022. Preload("User").
  2023. First(&gsc).Error
  2024. if err != nil {
  2025. e.Log.Errorf("db error: %s", err)
  2026. if errors.Is(err, gorm.ErrRecordNotFound) {
  2027. return errors.New(fmt.Sprintf("司机【%s】超期瓶%s不存在", allotUser.NickName, innerCode))
  2028. }
  2029. return errors.New(fmt.Sprintf("查询司机超期瓶失败"))
  2030. }
  2031. }
  2032. }
  2033. } else if allotUser.ProvUser.UserType == 5 {
  2034. // 气站到司机
  2035. if acceptUser.ProvUser.UserType == 4 && acceptUser.ProvUser.Isorders == 0 {
  2036. for _, innerCode := range innerCodeList {
  2037. // 查询气站超期瓶
  2038. var gsc model.GasCylinderStatus
  2039. err = e.Orm.Where("inner_code = ? and user_id = 0 and company_id = ? and status = ?",
  2040. innerCode, allotUser.Dept.Id, model.GasCylinderStatusExtended).
  2041. Preload("Company").
  2042. First(&gsc).Error
  2043. if err != nil {
  2044. e.Log.Errorf("db error: %s", err)
  2045. if errors.Is(err, gorm.ErrRecordNotFound) {
  2046. return errors.New(fmt.Sprintf("气站【%s】超期瓶%s不存在", allotUser.Dept.Name, innerCode))
  2047. }
  2048. return errors.New(fmt.Sprintf("查询气站超期瓶失败"))
  2049. }
  2050. }
  2051. }
  2052. }
  2053. }
  2054. return nil
  2055. }