Goodsfcode.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Goodsfcode extends BaseModel
  12. {
  13. /**
  14. * 插入数据
  15. * @access public
  16. * @author csdeshang
  17. * @param array $data 参数内容
  18. * @return boolean
  19. */
  20. public function addGoodsfcodeAll($data)
  21. {
  22. return Db::name('goodsfcode')->insertAll($data);
  23. }
  24. /**
  25. * 取得F码列表
  26. * @access public
  27. * @author csdeshang
  28. * @param type $condition 条件
  29. * @param type $order 排序
  30. * @return type
  31. */
  32. public function getGoodsfcodeList($condition, $order = 'goodsfcode_state asc,goodsfcode_id asc')
  33. {
  34. return Db::name('goodsfcode')->where($condition)->order($order)->select()->toArray();
  35. }
  36. /**
  37. * 删除F码
  38. * @access public
  39. * @author csdeshang
  40. * @param type $condition 条件
  41. * @return bool
  42. */
  43. public function delGoodsfcode($condition)
  44. {
  45. return Db::name('goodsfcode')->where($condition)->delete();
  46. }
  47. /**
  48. * 取得F码
  49. * @access public
  50. * @author csdeshang
  51. * @param type $condition 条件
  52. * @return bool
  53. */
  54. public function getGoodsfcode($condition)
  55. {
  56. return Db::name('goodsfcode')->where($condition)->find();
  57. }
  58. /**
  59. * 更新F码
  60. * @access public
  61. * @author csdeshang
  62. * @param array $data 更新数据
  63. * @param array $condition 条件
  64. * @return bool
  65. */
  66. public function editGoodsfcode($data, $condition)
  67. {
  68. return Db::name('goodsfcode')->where($condition)->update($data);
  69. }
  70. /**
  71. * 更新F码为使用状态
  72. * @param int $goodsfcode_id
  73. */
  74. public function updateGoodsfcode($goodsfcode_id)
  75. {
  76. $update = $this->editGoodsfcode(array('goodsfcode_state' => 1), array('goodsfcode_id' => $goodsfcode_id));
  77. if (!$update) {
  78. return ds_callback(false, '更新F码使用状态失败goodsfcode_id:' . $goodsfcode_id);
  79. } else {
  80. return ds_callback(true);
  81. }
  82. }
  83. /**
  84. * 生成商品F码
  85. */
  86. public function createGoodsfcode($param)
  87. {
  88. $insert = array();
  89. for ($i = 0; $i < $param['goodsfcode_count']; $i++) {
  90. $array = array();
  91. $array['goods_commonid'] = $param['goods_commonid'];
  92. $array['goodsfcode_code'] = strtoupper($param['goodsfcode_prefix']) . mt_rand(100000, 999999);
  93. $insert[$array['goodsfcode_code']] = $array;
  94. }
  95. if (!empty($insert)) {
  96. $insert = array_values($insert);
  97. $insert = $this->addGoodsfcodeAll($insert);
  98. if (!$insert) {
  99. return ds_callback(false, '生成商品F码失败goods_commonid:' . $param['goods_commonid']);
  100. }
  101. }
  102. return ds_callback(true);
  103. }
  104. }