payordermodel.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\index\model;
  3. use think\Model;
  4. class payordermodel extends Model
  5. {
  6. public function insertData($data)
  7. {
  8. if (!isset($data['create_date']) || empty($data['create_date']) || !is_string($data['create_date'])) {
  9. $data['create_date'] = date("Y-m-d H:i:s");
  10. }
  11. if (isset($data['id'])) {
  12. unset($data['id']);
  13. }
  14. $data = $this->formatData($data);
  15. if (empty($data)) {
  16. return false;
  17. }
  18. $id = $this->insertGetId($data);
  19. return $id ? $id : false;
  20. }
  21. /**
  22. * 校验入库数据
  23. * 20220119
  24. */
  25. private function formatData($data)
  26. {
  27. $useData = [];
  28. $fields = $this->getTableFields();
  29. foreach ($data as $key => $value) {
  30. if (in_array($key, $fields)) {
  31. $useData[$key] = $value;
  32. }
  33. }
  34. return $useData;
  35. }
  36. public function getInfo($where, $field = "*", $row = true)
  37. {
  38. $info = $this->field($field)->where($where);
  39. if ($row) {
  40. $info = $info->find();
  41. } else {
  42. $info = $info->select();
  43. }
  44. return empty($info) ? false : $info;
  45. }
  46. public function updateinfo($where, $updateData)
  47. {
  48. $row = $this->where($where)->update($updateData);
  49. return empty($row) ? false : $row;
  50. }
  51. public function deleteinfo($where)
  52. {
  53. $row = $this->where($where)->delete();
  54. return empty($row) ? false : $row;
  55. }
  56. public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
  57. {
  58. $sqlObj = $this->where($where);
  59. if ("count" != $field) {
  60. $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
  61. if ($row) {
  62. $data = $sqlObj->find();
  63. } else {
  64. $data = $sqlObj->select();
  65. }
  66. } else {
  67. $data = $sqlObj = $sqlObj->count();
  68. }
  69. return $data;
  70. }
  71. /**
  72. * 根据商户订单号获取订单信息
  73. *
  74. * @param [type] $outorderno
  75. * @return void
  76. * @author wj
  77. * @date 2022-07-23
  78. */
  79. public function getorderinfobyoutorderno($outorderno)
  80. {
  81. $where = ['outorderno' => $outorderno];
  82. $info = $this->where($where)->find();
  83. return $info ? $info : false;
  84. }
  85. /**
  86. * 根据id改数据
  87. *
  88. * @param [type] $id
  89. * @param [type] $updateData
  90. * @return void
  91. * @author wj
  92. * @date 2022-07-23
  93. */
  94. public function updateinfobyid($id, $updateData)
  95. {
  96. $where = ['id' => $id];
  97. $row = $this->where($where)->upate($updateData);
  98. return $row ? $row : false;
  99. }
  100. }