123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- package controllers
-
- import (
- "Xcx_New/enums"
- "Xcx_New/models"
- "Xcx_New/service"
- "Xcx_New/utils"
- "github.com/astaxie/beego"
- "github.com/jinzhu/gorm"
- "strconv"
- "time"
- )
-
- type StockApiController struct {
- BaseAuthAPIController
- }
-
- func StockApiRegistRouters() {
- beego.Router("/api/stock/dealer/create", &StockApiController{}, "post:CreateDealer")
- beego.Router("/api/stock/dealer/modify", &StockApiController{}, "post:ModifyDealer")
- beego.Router("/api/stock/dealer/list", &StockApiController{}, "get:GetDealersList")
- beego.Router("/api/stock/dealer/delete", &StockApiController{}, "post:DeleteDealer")
- beego.Router("/api/stock/dealer/get", &StockApiController{}, "get:GetDealer")
-
- beego.Router("/api/stock/manufacturer/create", &StockApiController{}, "post:CreateManufacturer")
- beego.Router("/api/stock/manufacturer/modify", &StockApiController{}, "post:ModifyManufacturer")
- beego.Router("/api/stock/manufacturer/list", &StockApiController{}, "get:GetManufacturerList")
- beego.Router("/api/stock/manufacturer/delete", &StockApiController{}, "post:DeleteManufacturer")
- beego.Router("/api/stock/manufacturer/get", &StockApiController{}, "get:GetManufacturer")
-
- beego.Router("/api/stock/dealer/all", &StockApiController{}, "get:GetAllDealer")
- beego.Router("/api/stock/manufacturer/all", &StockApiController{}, "get:GetAllManufacturer")
-
- }
-
- func (c *StockApiController) CreateDealer() {
- dealer_name := c.GetString("dealer_name")
- contact := c.GetString("contact")
- contact_phone := c.GetString("contact_phone")
- platform_number := c.GetString("platform_number")
- email := c.GetString("email")
- contact_address := c.GetString("contact_address")
- remark := c.GetString("remark")
- wubi := c.GetString("wubi")
- pinyin := c.GetString("pinyin")
-
- if len(dealer_name) <= 0 {
- utils.ErrorLog("len(dealer_name) == 0")
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- total := service.FindAllDealerTotal(adminUserInfo.CurrentOrgId)
- totalStr := strconv.FormatInt(total+1, 10)
- code := "1000" + totalStr
- dealer := models.Dealer{
- DealerName: dealer_name,
- Contact: contact,
- ContactPhone: contact_phone,
- ContactAddress: contact_address,
- DealerCode: code,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Remark: remark,
- Creater: adminUserInfo.AdminUser.Id,
- Email: email,
- PlatformNumber: platform_number,
- OrgId: adminUserInfo.CurrentOrgId,
- Status: 1,
- WuBi: wubi,
- PinYin: pinyin,
- }
-
- err, dealers := service.AddSigleDealer(&dealer)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "dealer": dealers,
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
-
- }
-
- }
- func (c *StockApiController) ModifyDealer() {
- id, _ := c.GetInt64("id", 0)
- dealer_name := c.GetString("dealer_name")
- contact := c.GetString("contact")
- contact_phone := c.GetString("contact_phone")
- platform_number := c.GetString("platform_number")
- dealer_code := c.GetString("dealer_code")
- email := c.GetString("email")
- contact_address := c.GetString("contact_address")
- remark := c.GetString("remark")
- wubi := c.GetString("wubi")
- pinyin := c.GetString("pinyin")
-
- if id <= 0 {
- utils.ErrorLog("id == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(dealer_name) <= 0 {
- utils.ErrorLog("len(dealer_name) == 0")
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- dealer := models.Dealer{
- ID: id,
- DealerName: dealer_name,
- Contact: contact,
- ContactPhone: contact_phone,
- ContactAddress: contact_address,
- Mtime: time.Now().Unix(),
- DealerCode: dealer_code,
- Remark: remark,
- Creater: adminUserInfo.AdminUser.Id,
- Email: email,
- PlatformNumber: platform_number,
- Modifier: adminUserInfo.AdminUser.Id,
- OrgId: adminUserInfo.CurrentOrgId,
- Status: 1,
- WuBi: wubi,
- PinYin: pinyin,
- }
-
- err := service.ModifyDealer(&dealer)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "dealer": dealer,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockApiController) GetDealersList() {
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 7)
- adminUserInfo := c.GetAdminUserInfo()
- deales, total, err := service.FindAllDealerList(adminUserInfo.CurrentOrgId, page, limit)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "dealer": deales,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockApiController) DeleteDealer() {
- id, _ := c.GetInt64("id", 0)
- total, _ := service.FindStockInByDealerId(id)
- if total > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteDealerWrong)
- return
- }
- err := service.DeleteDealerById(id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- func (c *StockApiController) GetDealer() {
- id, _ := c.GetInt64("id", 0)
- dealer, err := service.FindDealerById(id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "dealer": dealer,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- func (c *StockApiController) CreateManufacturer() {
- manufacturer_name := c.GetString("manufacturer_name")
- contact := c.GetString("contact")
- contact_phone := c.GetString("contact_phone")
- platform_number := c.GetString("platform_number")
- email := c.GetString("email")
- contact_address := c.GetString("contact_address")
- remark := c.GetString("remark")
- wubi := c.GetString("wubi")
- pinyin := c.GetString("pinyin")
-
- if len(manufacturer_name) <= 0 {
- utils.ErrorLog("len(manufacturer_name) == 0")
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- total := service.FindManufacturerTotal(adminUserInfo.CurrentOrgId)
- totalStr := strconv.FormatInt(total+1, 10)
- code := "2000" + totalStr
- manufacturer := models.Manufacturer{
- ManufacturerName: manufacturer_name,
- Contact: contact,
- ContactPhone: contact_phone,
- ContactAddress: contact_address,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Remark: remark,
- Creater: adminUserInfo.AdminUser.Id,
- Email: email,
- PlatformNumber: platform_number,
- OrgId: adminUserInfo.CurrentOrgId,
- Status: 1,
- ManufacturerCode: code,
- WuBi: wubi,
- PinYin: pinyin,
- }
-
- _, errcode := service.GetManufacturerName(adminUserInfo.CurrentOrgId, manufacturer_name)
- if errcode == gorm.ErrRecordNotFound {
- err, manufacturers := service.AddSigleManufacturer(&manufacturer)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "manufacturer": manufacturers,
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- } else if errcode == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
- func (c *StockApiController) ModifyManufacturer() {
-
- id, _ := c.GetInt64("id", 0)
- manufacturer_name := c.GetString("manufacturer_name")
- contact := c.GetString("contact")
- contact_phone := c.GetString("contact_phone")
- platform_number := c.GetString("platform_number")
- email := c.GetString("email")
- contact_address := c.GetString("contact_address")
- remark := c.GetString("remark")
- manufacturer_code := c.GetString("manufacturer_code")
- wubi := c.GetString("wubi")
- pinyin := c.GetString("pinyin")
-
- if id <= 0 {
- utils.ErrorLog("id == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(manufacturer_name) <= 0 {
- utils.ErrorLog("len(manufacturer_name) == 0")
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- manufacturer := models.Manufacturer{
- ID: id,
- ManufacturerName: manufacturer_name,
- Contact: contact,
- ContactPhone: contact_phone,
- ContactAddress: contact_address,
- Mtime: time.Now().Unix(),
- Remark: remark,
- Creater: adminUserInfo.AdminUser.Id,
- Email: email,
- PlatformNumber: platform_number,
- Modifier: adminUserInfo.AdminUser.Id,
- OrgId: adminUserInfo.CurrentOrgId,
- ManufacturerCode: manufacturer_code,
- Status: 1,
- WuBi: wubi,
- PinYin: pinyin,
- }
-
- _, errrcode := service.GetManufacturerName(adminUserInfo.CurrentOrgId, manufacturer_name)
-
- if errrcode == nil {
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
-
- return
- }
-
- err := service.ModifyManufacturer(&manufacturer)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "manufacturer": manufacturer,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
- func (c *StockApiController) GetManufacturerList() {
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 10)
- adminUserInfo := c.GetAdminUserInfo()
- manufacturer, total, err := service.FindAllManufacturerList(adminUserInfo.CurrentOrgId, page, limit)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "manufacturer": manufacturer,
- "total": total,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockApiController) DeleteManufacturer() {
- id, _ := c.GetInt64("id", 0)
- total, _ := service.FindStockInByManufacturerId(id)
- if total > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteManufacturerWrong)
- return
- }
-
- err := service.DeleteManufacturerById(id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- func (c *StockApiController) GetManufacturer() {
- id, _ := c.GetInt64("id", 0)
- manufacturer, err := service.FindManufacturerById(id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "manufacturer": manufacturer,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
-
- func (c *StockApiController) GetAllDealer() {
- adminUserInfo := c.GetAdminUserInfo()
- dealer, err := service.FindAllDealer(adminUserInfo.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "dealer": dealer,
- })
- } else {
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- func (c *StockApiController) GetAllManufacturer() {
- adminUserInfo := c.GetAdminUserInfo()
- manufacturer, err := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "manufacturer": manufacturer,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
|